@etherisc/gif-next 0.0.2-da77c50-824 → 0.0.2-dc7e4cb-141
Sign up to get free protection for your applications and to get access to all the features.
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +2 -2
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +2 -2
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +6 -11
- package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/IServiceLinked.sol/IServiceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +71 -86
- package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +5 -5
- package/artifacts/contracts/instance/module/access/Access.sol/AccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/access/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/module/access/IAccess.sol/IAccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/bundle/BundleModule.sol/BundleModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/bundle/IBundle.sol/IBundleModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.dbg.json +4 -0
- package/artifacts/contracts/instance/module/compensation/CompensationModule.sol/CompensationModule.json +10 -0
- package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensation.dbg.json +4 -0
- package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensation.json +10 -0
- package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensationModule.dbg.json +4 -0
- package/artifacts/contracts/instance/module/compensation/ICompensation.sol/ICompensationModule.json +10 -0
- package/artifacts/contracts/instance/module/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/component/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/instance/module/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/module/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPool.dbg.json +1 -1
- package/artifacts/contracts/instance/module/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/risk/IRisk.sol/IRisk.dbg.json +4 -0
- package/artifacts/contracts/instance/module/{product/ProductModule.sol/ProductModule.json → risk/IRisk.sol/IRisk.json} +2 -2
- package/artifacts/contracts/instance/module/risk/IRisk.sol/IRiskModule.dbg.json +4 -0
- package/artifacts/contracts/instance/module/{product/IProductModule.sol/IProductModule.json → risk/IRisk.sol/IRiskModule.json} +2 -2
- package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.dbg.json +4 -0
- package/artifacts/contracts/instance/module/risk/RiskModule.sol/RiskModule.json +10 -0
- package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasury.dbg.json +1 -1
- package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/treasury/ITreasury.sol/ITreasuryModule.json +1 -6
- package/artifacts/contracts/instance/module/treasury/TokenHandler.sol/TokenHandler.dbg.json +1 -1
- package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +1 -1
- package/artifacts/contracts/instance/module/treasury/TreasuryModule.sol/TreasuryModule.json +1 -6
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +25 -53
- package/artifacts/contracts/instance/service/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ComponentServiceBase.sol/ComponentServiceBase.json +5 -5
- package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.json +5 -5
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.json +5 -5
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.json +5 -5
- package/artifacts/contracts/instance/service/IService.sol/IService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IService.sol/IService.json +5 -5
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +18 -46
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +47 -59
- package/artifacts/contracts/instance/service/ServiceBase.sol/ServiceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ServiceBase.sol/ServiceBase.json +5 -5
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistryLinked.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +2 -2
- package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/contracts/shared/IOwnable.sol/IOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
- package/artifacts/contracts/shared/IVersionable.sol/IVersionable.json +5 -5
- package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
- package/artifacts/contracts/shared/Versionable.sol/Versionable.json +5 -5
- package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
- package/artifacts/contracts/test/TestFee.sol/TestFee.json +28 -4
- package/artifacts/contracts/test/TestPool.sol/TestPool.dbg.json +1 -1
- package/artifacts/contracts/test/TestPool.sol/TestPool.json +2 -2
- package/artifacts/contracts/test/TestProduct.sol/TestProduct.dbg.json +1 -1
- package/artifacts/contracts/test/TestProduct.sol/TestProduct.json +2 -2
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.json +15 -43
- package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +14 -18
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +15 -39
- package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +4 -0
- package/artifacts/contracts/test/Usdc.sol/USDC.json +338 -0
- package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +4 -0
- package/artifacts/contracts/types/Fee.sol/FeeLib.json +218 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +34 -8
- package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionLib.json +63 -2
- package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionPartLib.json +2 -2
- package/contracts/instance/IInstance.sol +4 -1
- package/contracts/instance/Instance.sol +4 -0
- package/contracts/instance/InstanceBase.sol +2 -5
- package/contracts/instance/module/compensation/CompensationModule.sol +8 -0
- package/contracts/instance/module/compensation/ICompensation.sol +10 -0
- package/contracts/instance/module/component/ComponentModule.sol +1 -2
- package/contracts/instance/module/{product/IProductModule.sol → risk/IRisk.sol} +6 -2
- package/contracts/instance/module/risk/RiskModule.sol +8 -0
- package/contracts/instance/module/treasury/ITreasury.sol +2 -3
- package/contracts/instance/module/treasury/TreasuryModule.sol +15 -11
- package/contracts/instance/service/ComponentOwnerService.sol +3 -6
- package/contracts/instance/service/PoolService.sol +35 -10
- package/contracts/instance/service/ProductService.sol +5 -8
- package/contracts/instance/service/ServiceBase.sol +1 -1
- package/contracts/shared/IVersionable.sol +2 -2
- package/contracts/shared/Versionable.sol +3 -6
- package/contracts/test/TestFee.sol +3 -3
- package/contracts/test/TestPool.sol +1 -1
- package/contracts/test/TestProduct.sol +1 -1
- package/contracts/test/TestService.sol +2 -5
- package/contracts/test/TestVersion.sol +4 -7
- package/contracts/test/TestVersionable.sol +2 -5
- package/contracts/test/Usdc.sol +26 -0
- package/contracts/types/Fee.sol +39 -20
- package/contracts/types/UFixed.sol +19 -16
- package/contracts/types/Version.sol +29 -25
- package/package.json +1 -1
- package/artifacts/contracts/instance/module/product/IProductModule.sol/IProductModule.dbg.json +0 -4
- package/artifacts/contracts/instance/module/product/ProductModule.sol/ProductModule.dbg.json +0 -4
- package/contracts/instance/module/product/ProductModule.sol +0 -8
@@ -3,13 +3,12 @@ pragma solidity ^0.8.19;
|
|
3
3
|
|
4
4
|
import {Blocknumber, blockNumber} from "../types/Blocknumber.sol";
|
5
5
|
import {Timestamp, blockTimestamp} from "../types/Timestamp.sol";
|
6
|
-
import {Version, VersionPart
|
6
|
+
import {Version, VersionPart} from "../types/Version.sol";
|
7
7
|
|
8
8
|
import {IVersionable} from "./IVersionable.sol";
|
9
9
|
|
10
10
|
abstract contract Versionable is IVersionable {
|
11
11
|
|
12
|
-
|
13
12
|
mapping(Version version => VersionInfo info) private _versionHistory;
|
14
13
|
Version [] private _versions;
|
15
14
|
|
@@ -58,8 +57,8 @@ abstract contract Versionable is IVersionable {
|
|
58
57
|
thisVersion,
|
59
58
|
implementation,
|
60
59
|
activatedBy,
|
61
|
-
|
62
|
-
|
60
|
+
blockTimestamp(),
|
61
|
+
blockNumber()
|
63
62
|
);
|
64
63
|
|
65
64
|
emit LogVersionableActivated(thisVersion, implementation, activatedBy);
|
@@ -80,13 +79,11 @@ abstract contract Versionable is IVersionable {
|
|
80
79
|
|
81
80
|
|
82
81
|
function getVersion(uint256 idx) external view override returns(Version) {
|
83
|
-
require(idx < _versions.length, "ERROR:VRN-010:INDEX_TOO_LARGE");
|
84
82
|
return _versions[idx];
|
85
83
|
}
|
86
84
|
|
87
85
|
|
88
86
|
function getVersionInfo(Version _version) external override view returns(VersionInfo memory) {
|
89
|
-
require(isActivated(_version), "ERROR:VRN-020:VERSION_UNKNOWN");
|
90
87
|
return _versionHistory[_version];
|
91
88
|
}
|
92
89
|
}
|
@@ -2,7 +2,7 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
import {UFixed, UFixedMathLib} from "../types/UFixed.sol";
|
5
|
-
import {Fee,
|
5
|
+
import {Fee, FeeLib} from "../types/Fee.sol";
|
6
6
|
|
7
7
|
contract TestFee {
|
8
8
|
|
@@ -15,11 +15,11 @@ contract TestFee {
|
|
15
15
|
pure
|
16
16
|
returns(Fee memory fee)
|
17
17
|
{
|
18
|
-
return toFee(UFixedMathLib.toUFixed(fractionalValue, exponent), fixedValue);
|
18
|
+
return FeeLib.toFee(UFixedMathLib.toUFixed(fractionalValue, exponent), fixedValue);
|
19
19
|
}
|
20
20
|
|
21
21
|
function getZeroFee() external pure returns(Fee memory fee) {
|
22
|
-
return zeroFee();
|
22
|
+
return FeeLib.zeroFee();
|
23
23
|
}
|
24
24
|
|
25
25
|
}
|
@@ -3,7 +3,7 @@ pragma solidity ^0.8.19;
|
|
3
3
|
|
4
4
|
import {NftId} from "../../contracts/types/NftId.sol";
|
5
5
|
import {UFixed} from "../../contracts/types/UFixed.sol";
|
6
|
-
import {Fee
|
6
|
+
import {Fee} from "../../contracts/types/Fee.sol";
|
7
7
|
import {Pool} from "../../contracts/components/Pool.sol";
|
8
8
|
|
9
9
|
|
@@ -4,7 +4,7 @@ pragma solidity ^0.8.19;
|
|
4
4
|
import {Product} from "../../contracts/components/Product.sol";
|
5
5
|
import {NftId, toNftId} from "../../contracts/types/NftId.sol";
|
6
6
|
import {Timestamp, blockTimestamp} from "../../contracts/types/Timestamp.sol";
|
7
|
-
import {Fee
|
7
|
+
import {Fee} from "../../contracts/types/Fee.sol";
|
8
8
|
|
9
9
|
contract TestProduct is Product {
|
10
10
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
import {NftId} from "../../contracts/types/NftId.sol";
|
5
|
-
import {Version,
|
5
|
+
import {Version, VersionLib} from "../../contracts/types/Version.sol";
|
6
6
|
import {ServiceBase} from "../../contracts/instance/service/ServiceBase.sol";
|
7
7
|
|
8
8
|
import {IVersionable} from "../../contracts/shared/IVersionable.sol";
|
@@ -23,10 +23,7 @@ contract TestService is ServiceBase {
|
|
23
23
|
virtual override (IVersionable, Versionable)
|
24
24
|
returns(Version)
|
25
25
|
{
|
26
|
-
return toVersion(
|
27
|
-
toVersionPart(3),
|
28
|
-
toVersionPart(0),
|
29
|
-
toVersionPart(0));
|
26
|
+
return VersionLib.toVersion(3,0,0);
|
30
27
|
}
|
31
28
|
|
32
29
|
function getName() external pure override returns(string memory name) {
|
@@ -1,19 +1,16 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
import {Version, VersionPart,
|
4
|
+
import {Version, VersionPart, VersionLib} from "../types/Version.sol";
|
5
5
|
|
6
6
|
contract TestVersion {
|
7
7
|
|
8
8
|
function createVersion(uint major, uint minor, uint patch) external pure returns(Version) {
|
9
|
-
return toVersion(
|
10
|
-
toVersionPart(uint8(major)),
|
11
|
-
toVersionPart(uint8(minor)),
|
12
|
-
toVersionPart(uint8(patch)));
|
9
|
+
return VersionLib.toVersion(major, minor, patch);
|
13
10
|
}
|
14
11
|
|
15
12
|
function createVersionPart(uint versionPart) external pure returns(VersionPart) {
|
16
|
-
return toVersionPart(uint8(versionPart));
|
13
|
+
return VersionLib.toVersionPart(uint8(versionPart));
|
17
14
|
}
|
18
15
|
|
19
16
|
function getVersionParts(Version version)
|
@@ -33,7 +30,7 @@ contract TestVersion {
|
|
33
30
|
}
|
34
31
|
|
35
32
|
function getZeroVersion() external pure returns(Version) {
|
36
|
-
return zeroVersion();
|
33
|
+
return VersionLib.zeroVersion();
|
37
34
|
}
|
38
35
|
|
39
36
|
function isSameVersion(Version a, Version b) external pure returns(bool) {
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
import {Version,
|
4
|
+
import {Version, VersionLib} from "../../contracts/types/Version.sol";
|
5
5
|
import {Versionable} from "../../contracts/shared/Versionable.sol";
|
6
6
|
|
7
7
|
contract TestVersionable is Versionable {
|
@@ -12,9 +12,6 @@ contract TestVersionable is Versionable {
|
|
12
12
|
virtual override
|
13
13
|
returns(Version)
|
14
14
|
{
|
15
|
-
return toVersion(
|
16
|
-
toVersionPart(3),
|
17
|
-
toVersionPart(0),
|
18
|
-
toVersionPart(0));
|
15
|
+
return VersionLib.toVersion(3,0,0);
|
19
16
|
}
|
20
17
|
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
5
|
+
|
6
|
+
contract USDC is ERC20 {
|
7
|
+
|
8
|
+
// https://etherscan.io/token/0xc719d010b63e5bbf2c0551872cd5316ed26acd83#readContract
|
9
|
+
string public constant NAME = "USDC - DUMMY";
|
10
|
+
string public constant SYMBOL = "USDC";
|
11
|
+
uint8 public constant DECIMALS = 6;
|
12
|
+
uint256 public constant INITIAL_SUPPLY = 10**9 * 10**DECIMALS; // 1 Billion 1'000'000'000
|
13
|
+
// decimals == 18 (openzeppelin erc20 default)
|
14
|
+
constructor()
|
15
|
+
ERC20(NAME, SYMBOL)
|
16
|
+
{
|
17
|
+
_mint(
|
18
|
+
_msgSender(),
|
19
|
+
INITIAL_SUPPLY
|
20
|
+
);
|
21
|
+
}
|
22
|
+
|
23
|
+
function decimals() public pure override returns(uint8) {
|
24
|
+
return DECIMALS;
|
25
|
+
}
|
26
|
+
}
|
package/contracts/types/Fee.sol
CHANGED
@@ -1,32 +1,51 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
import {UFixed} from "./UFixed.sol";
|
4
|
+
import {UFixed, UFixedMathLib} from "./UFixed.sol";
|
5
5
|
|
6
6
|
struct Fee {
|
7
7
|
UFixed fractionalFee;
|
8
8
|
uint256 fixedFee;
|
9
9
|
}
|
10
10
|
|
11
|
-
|
12
|
-
/// @dev Converts the uint256 to a NftId.
|
13
|
-
function toFee(
|
14
|
-
UFixed fractionalFee,
|
15
|
-
uint256 fixedFee
|
16
|
-
) pure returns (Fee memory fee) {
|
17
|
-
return Fee(fractionalFee, fixedFee);
|
18
|
-
}
|
11
|
+
library FeeLib {
|
19
12
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
function calculateFee(
|
14
|
+
uint256 amount,
|
15
|
+
Fee memory fee
|
16
|
+
)
|
17
|
+
public
|
18
|
+
pure
|
19
|
+
returns (
|
20
|
+
uint256 feeAmount,
|
21
|
+
uint256 netAmount
|
22
|
+
)
|
23
|
+
{
|
24
|
+
UFixed fractionalAmount = UFixedMathLib.toUFixed(amount) *
|
25
|
+
fee.fractionalFee;
|
26
|
+
feeAmount = fractionalAmount.toInt() + fee.fixedFee;
|
27
|
+
netAmount = amount - feeAmount;
|
28
|
+
}
|
24
29
|
|
25
|
-
|
26
|
-
function
|
27
|
-
|
28
|
-
|
30
|
+
/// @dev Converts the uint256 to a fee struct.
|
31
|
+
function toFee(
|
32
|
+
UFixed fractionalFee,
|
33
|
+
uint256 fixedFee
|
34
|
+
) public pure returns (Fee memory fee) {
|
35
|
+
return Fee(fractionalFee, fixedFee);
|
36
|
+
}
|
29
37
|
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
/// @dev Return the zero fee struct (0, 0)
|
39
|
+
function zeroFee() public pure returns (Fee memory fee) {
|
40
|
+
return Fee(UFixed.wrap(0), 0);
|
41
|
+
}
|
42
|
+
|
43
|
+
// pure free functions for operators
|
44
|
+
function feeIsSame(Fee memory a, Fee memory b) public pure returns (bool isSame) {
|
45
|
+
return a.fixedFee == b.fixedFee && a.fractionalFee == b.fractionalFee;
|
46
|
+
}
|
47
|
+
|
48
|
+
function feeIsZero(Fee memory fee) public pure returns (bool) {
|
49
|
+
return fee.fixedFee == 0 && UFixed.unwrap(fee.fractionalFee) == 0;
|
50
|
+
}
|
51
|
+
}
|
@@ -77,19 +77,25 @@ function deltaUFixed(UFixed a, UFixed b) pure returns (UFixed) {
|
|
77
77
|
}
|
78
78
|
|
79
79
|
library UFixedMathLib {
|
80
|
-
enum Rounding {
|
81
|
-
/// @dev Round down - floor(value)
|
82
|
-
Down,
|
83
|
-
/// @dev Round up - ceil(value)
|
84
|
-
Up,
|
85
|
-
/// @dev Round half up - round(value)
|
86
|
-
HalfUp
|
87
|
-
}
|
88
|
-
|
89
80
|
int8 public constant EXP = 18;
|
90
81
|
uint256 public constant MULTIPLIER = 10 ** uint256(int256(EXP));
|
91
82
|
uint256 public constant MULTIPLIER_HALF = MULTIPLIER / 2;
|
92
83
|
|
84
|
+
/// @dev returns the rounding mode DOWN - 0.4 becomes 0, 0.5 becomes 0, 0.6 becomes 0
|
85
|
+
function ROUNDING_DOWN() public pure returns (uint8) {
|
86
|
+
return uint8(0);
|
87
|
+
}
|
88
|
+
|
89
|
+
/// @dev returns the rounding mode UP - 0.4 becomes 1, 0.5 becomes 1, 0.6 becomes 1
|
90
|
+
function ROUNDING_UP() public pure returns (uint8) {
|
91
|
+
return uint8(1);
|
92
|
+
}
|
93
|
+
|
94
|
+
/// @dev returns the rounding mode HALF_UP - 0.4 becomes 0, 0.5 becomes 1, 0.6 becomes 1
|
95
|
+
function ROUNDING_HALF_UP() public pure returns (uint8) {
|
96
|
+
return uint8(2);
|
97
|
+
}
|
98
|
+
|
93
99
|
/// @dev Converts the uint256 to a UFixed.
|
94
100
|
function toUFixed(uint256 a) public pure returns (UFixed) {
|
95
101
|
return UFixed.wrap(a * MULTIPLIER);
|
@@ -103,9 +109,6 @@ library UFixedMathLib {
|
|
103
109
|
return UFixed.wrap(a * 10 ** uint8(EXP + exp));
|
104
110
|
}
|
105
111
|
|
106
|
-
/// @dev Default rounding mode used by ftoi is HalfUp
|
107
|
-
Rounding public constant ROUNDING_DEFAULT = Rounding.HalfUp;
|
108
|
-
|
109
112
|
/// @dev returns the decimals precision of the UFixed type
|
110
113
|
function decimals() public pure returns (uint256) {
|
111
114
|
return uint8(EXP);
|
@@ -113,12 +116,12 @@ library UFixedMathLib {
|
|
113
116
|
|
114
117
|
/// @dev Converts a UFixed to a uint256.
|
115
118
|
function toInt(UFixed a) public pure returns (uint256) {
|
116
|
-
return toIntWithRounding(a,
|
119
|
+
return toIntWithRounding(a, ROUNDING_HALF_UP());
|
117
120
|
}
|
118
121
|
|
119
122
|
/// @dev Converts a UFixed to a uint256 with given rounding mode.
|
120
|
-
function toIntWithRounding(UFixed a,
|
121
|
-
if (rounding ==
|
123
|
+
function toIntWithRounding(UFixed a, uint8 rounding) public pure returns (uint256) {
|
124
|
+
if (rounding == ROUNDING_HALF_UP()) {
|
122
125
|
return
|
123
126
|
Math.mulDiv(
|
124
127
|
UFixed.unwrap(a) + MULTIPLIER_HALF,
|
@@ -126,7 +129,7 @@ library UFixedMathLib {
|
|
126
129
|
MULTIPLIER,
|
127
130
|
Math.Rounding.Down
|
128
131
|
);
|
129
|
-
} else if (rounding ==
|
132
|
+
} else if (rounding == ROUNDING_DOWN()) {
|
130
133
|
return
|
131
134
|
Math.mulDiv(
|
132
135
|
UFixed.unwrap(a),
|
@@ -12,7 +12,6 @@ using {
|
|
12
12
|
|
13
13
|
function versionPartGt(VersionPart a, VersionPart b) pure returns(bool isGreaterThan) { return VersionPart.unwrap(a) > VersionPart.unwrap(b); }
|
14
14
|
function versionPartEq(VersionPart a, VersionPart b) pure returns(bool isSame) { return VersionPart.unwrap(a) == VersionPart.unwrap(b); }
|
15
|
-
function toVersionPart(uint8 versionPart) pure returns(VersionPart) { return VersionPart.wrap(versionPart); }
|
16
15
|
|
17
16
|
library VersionPartLib {
|
18
17
|
function toInt(VersionPart x) external pure returns(uint) { return VersionPart.unwrap(x); }
|
@@ -32,27 +31,6 @@ using {
|
|
32
31
|
function versionGt(Version a, Version b) pure returns(bool isGreaterThan) { return Version.unwrap(a) > Version.unwrap(b); }
|
33
32
|
function versionEq(Version a, Version b) pure returns(bool isSame) { return Version.unwrap(a) == Version.unwrap(b); }
|
34
33
|
|
35
|
-
function toVersion(
|
36
|
-
VersionPart major,
|
37
|
-
VersionPart minor,
|
38
|
-
VersionPart patch
|
39
|
-
)
|
40
|
-
pure
|
41
|
-
returns(Version)
|
42
|
-
{
|
43
|
-
uint majorInt = major.toInt();
|
44
|
-
uint minorInt = minor.toInt();
|
45
|
-
uint patchInt = patch.toInt();
|
46
|
-
|
47
|
-
return Version.wrap(
|
48
|
-
uint24(
|
49
|
-
(majorInt << 16) + (minorInt << 8) + patchInt));
|
50
|
-
}
|
51
|
-
|
52
|
-
function zeroVersion() pure returns(Version) {
|
53
|
-
return toVersion(toVersionPart(0), toVersionPart(0), toVersionPart(0));
|
54
|
-
}
|
55
|
-
|
56
34
|
library VersionLib {
|
57
35
|
function toInt(Version version) external pure returns(uint) { return Version.unwrap(version); }
|
58
36
|
|
@@ -83,9 +61,35 @@ library VersionLib {
|
|
83
61
|
uint8 patchInt = uint8(versionInt - (minorInt << 8));
|
84
62
|
|
85
63
|
return (
|
86
|
-
|
87
|
-
|
88
|
-
|
64
|
+
VersionPart.wrap(majorInt),
|
65
|
+
VersionPart.wrap(minorInt),
|
66
|
+
VersionPart.wrap(patchInt)
|
89
67
|
);
|
90
68
|
}
|
69
|
+
|
70
|
+
function toVersionPart(uint256 versionPart) external pure returns(VersionPart) {
|
71
|
+
return VersionPart.wrap(uint8(versionPart));
|
72
|
+
}
|
73
|
+
|
74
|
+
function toVersion(
|
75
|
+
uint256 major,
|
76
|
+
uint256 minor,
|
77
|
+
uint256 patch
|
78
|
+
)
|
79
|
+
external
|
80
|
+
pure
|
81
|
+
returns(Version)
|
82
|
+
{
|
83
|
+
require(
|
84
|
+
major < 256 && minor < 256 && patch < 256,
|
85
|
+
"ERROR:VRS-010:VERSION_PART_TOO_BIG");
|
86
|
+
|
87
|
+
return Version.wrap(
|
88
|
+
uint24(
|
89
|
+
(major << 16) + (minor << 8) + patch));
|
90
|
+
}
|
91
|
+
|
92
|
+
function zeroVersion() external pure returns(Version) {
|
93
|
+
return Version.wrap(0);
|
94
|
+
}
|
91
95
|
}
|
package/package.json
CHANGED