@etherisc/gif-next 0.0.2-efdb520-159 → 0.0.2-f08d150-296
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/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/Dummy.sol/LifeCycleModule.json +2 -2
- 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/SM.sol/SM.json +2 -2
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
- 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 +48 -204
- package/artifacts/contracts/instance/IInstanceLinked.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +211 -303
- package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +4 -0
- package/artifacts/contracts/instance/{service → base}/ComponentServiceBase.sol/ComponentServiceBase.json +6 -6
- package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
- package/artifacts/contracts/instance/{IServiceLinked.sol/IServiceLinked.json → base/IInstanceBase.sol/IInstanceBase.json} +15 -2
- package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +4 -0
- package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.json +511 -0
- package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +4 -0
- package/artifacts/contracts/instance/{module/lifecycle/ILifecycle.sol/ILifecycleModule.json → base/ILifecycle.sol/ILifecycle.json} +10 -77
- package/artifacts/contracts/instance/base/IService.sol/IService.dbg.json +4 -0
- package/artifacts/contracts/instance/{service → base}/IService.sol/IService.json +6 -6
- package/artifacts/contracts/instance/base/InstanceBase.sol/InstanceBase.dbg.json +4 -0
- package/artifacts/contracts/instance/{InstanceBase.sol → base/InstanceBase.sol}/InstanceBase.json +19 -6
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +4 -0
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.json +692 -0
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +4 -0
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.json +169 -0
- package/artifacts/contracts/instance/base/ModuleBase.sol/ModuleBase.dbg.json +4 -0
- package/artifacts/contracts/instance/{module/product/ProductModule.sol/ProductModule.json → base/ModuleBase.sol/ModuleBase.json} +2 -2
- package/artifacts/contracts/instance/base/ServiceBase.sol/ServiceBase.dbg.json +4 -0
- package/artifacts/contracts/instance/{service → base}/ServiceBase.sol/ServiceBase.json +6 -6
- 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/BundleModule.sol/BundleModule.json +50 -30
- 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/bundle/IBundle.sol/IBundleModule.json +50 -30
- 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/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/IProductModule.sol/IProductModule.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/risk/IRisk.sol/IRiskModule.json +10 -0
- 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/TokenHandler.sol/TokenHandler.json +2 -2
- 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 +48 -44
- 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/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/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/TestRoleId.sol/TestRoleId.json +38 -4
- 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/Key32.sol/Key32Lib.dbg.json +4 -0
- package/artifacts/contracts/types/Key32.sol/Key32Lib.json +111 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +65 -4
- package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
- package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.json +2 -2
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/RoleId.sol/RoleIdLib.json +30 -0
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
- 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/components/BaseComponent.sol +0 -1
- package/contracts/instance/IInstance.sol +13 -11
- package/contracts/instance/Instance.sol +13 -7
- package/contracts/instance/{service → base}/ComponentServiceBase.sol +1 -0
- package/contracts/instance/base/IInstanceBase.sol +14 -0
- package/contracts/instance/base/IKeyValueStore.sol +49 -0
- package/contracts/instance/base/ILifecycle.sol +30 -0
- package/contracts/instance/{InstanceBase.sol → base/InstanceBase.sol} +21 -15
- package/contracts/instance/base/KeyValueStore.sol +156 -0
- package/contracts/instance/{module/lifecycle/LifecycleModule.sol → base/Lifecycle.sol} +36 -30
- package/contracts/instance/base/ModuleBase.sol +52 -0
- package/contracts/instance/{service → base}/ServiceBase.sol +1 -3
- package/contracts/instance/module/access/Access.sol +3 -3
- package/contracts/instance/module/bundle/BundleModule.sol +24 -116
- package/contracts/instance/module/bundle/IBundle.sol +8 -3
- 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 +10 -19
- package/contracts/instance/module/policy/PolicyModule.sol +2 -10
- 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 +4 -8
- package/contracts/instance/service/IComponentOwnerService.sol +1 -1
- package/contracts/instance/service/IPoolService.sol +1 -1
- package/contracts/instance/service/IProductService.sol +1 -1
- package/contracts/instance/service/PoolService.sol +36 -11
- package/contracts/instance/service/ProductService.sol +6 -10
- package/contracts/registry/Registry.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/TestRoleId.sol +2 -2
- package/contracts/test/TestService.sol +3 -6
- 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/Key32.sol +45 -0
- package/contracts/types/NftId.sol +16 -1
- package/contracts/types/RoleId.sol +11 -9
- package/contracts/types/StateId.sol +7 -1
- package/contracts/types/UFixed.sol +19 -16
- package/contracts/types/Version.sol +29 -25
- package/package.json +1 -1
- package/artifacts/contracts/instance/IServiceLinked.sol/IServiceLinked.dbg.json +0 -4
- package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +0 -4
- package/artifacts/contracts/instance/module/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +0 -4
- package/artifacts/contracts/instance/module/lifecycle/ILifecycle.sol/ILifecycle.json +0 -134
- package/artifacts/contracts/instance/module/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +0 -4
- package/artifacts/contracts/instance/module/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +0 -4
- package/artifacts/contracts/instance/module/lifecycle/LifecycleModule.sol/LifecycleModule.json +0 -221
- 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/artifacts/contracts/instance/service/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +0 -4
- package/artifacts/contracts/instance/service/IService.sol/IService.dbg.json +0 -4
- package/artifacts/contracts/instance/service/ServiceBase.sol/ServiceBase.dbg.json +0 -4
- package/contracts/instance/IServiceLinked.sol +0 -12
- package/contracts/instance/module/lifecycle/ILifecycle.sol +0 -47
- package/contracts/instance/module/product/ProductModule.sol +0 -8
- /package/contracts/instance/{service → base}/IService.sol +0 -0
@@ -19,10 +19,10 @@ import {ObjectType, INSTANCE, PRODUCT, POLICY} from "../../types/ObjectType.sol"
|
|
19
19
|
import {APPLIED, UNDERWRITTEN, ACTIVE} from "../../types/StateId.sol";
|
20
20
|
import {NftId, NftIdLib} from "../../types/NftId.sol";
|
21
21
|
import {Blocknumber, blockNumber} from "../../types/Blocknumber.sol";
|
22
|
-
import {Fee,
|
23
|
-
import {Version,
|
22
|
+
import {Fee, FeeLib} from "../../types/Fee.sol";
|
23
|
+
import {Version, VersionLib} from "../../types/Version.sol";
|
24
24
|
|
25
|
-
import {ComponentServiceBase} from "
|
25
|
+
import {ComponentServiceBase} from "../base/ComponentServiceBase.sol";
|
26
26
|
import {IProductService} from "./IProductService.sol";
|
27
27
|
|
28
28
|
// TODO or name this ProtectionService to have Product be something more generic (loan, savings account, ...)
|
@@ -47,10 +47,7 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
47
47
|
virtual override (IVersionable, Versionable)
|
48
48
|
returns(Version)
|
49
49
|
{
|
50
|
-
return toVersion(
|
51
|
-
toVersionPart(3),
|
52
|
-
toVersionPart(0),
|
53
|
-
toVersionPart(0));
|
50
|
+
return VersionLib.toVersion(3,0,0);
|
54
51
|
}
|
55
52
|
|
56
53
|
function getName() external pure override returns(string memory name) {
|
@@ -137,7 +134,6 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
137
134
|
returns (IBundle.BundleInfo memory)
|
138
135
|
{
|
139
136
|
bundleInfo.lockedAmount += collateralAmount;
|
140
|
-
bundleInfo.updatedIn = blockNumber();
|
141
137
|
instance.collateralizePolicy(bundleInfo.nftId, policyNftId, collateralAmount);
|
142
138
|
return bundleInfo;
|
143
139
|
}
|
@@ -329,13 +325,13 @@ contract ProductService is ComponentServiceBase, IProductService {
|
|
329
325
|
{
|
330
326
|
// process token transfer(s)
|
331
327
|
if(premiumAmount > 0) {
|
332
|
-
TokenHandler tokenHandler = product.
|
328
|
+
TokenHandler tokenHandler = instance.getTokenHandler(product.productNftId);
|
333
329
|
address policyOwner = _registry.getOwner(policyNftId);
|
334
330
|
address poolWallet = instance.getPoolSetup(product.poolNftId).wallet;
|
335
331
|
netPremiumAmount = premiumAmount;
|
336
332
|
Fee memory policyFee = product.policyFee;
|
337
333
|
|
338
|
-
if (feeIsZero(policyFee)) {
|
334
|
+
if (FeeLib.feeIsZero(policyFee)) {
|
339
335
|
tokenHandler.transfer(
|
340
336
|
policyOwner,
|
341
337
|
poolWallet,
|
@@ -2,7 +2,7 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
import {IRegisterable} from "../shared/IRegisterable.sol";
|
5
|
-
import {IService} from "../instance/
|
5
|
+
import {IService} from "../instance/base/IService.sol";
|
6
6
|
|
7
7
|
import {IChainNft} from "./IChainNft.sol";
|
8
8
|
import {ChainNft} from "./ChainNft.sol";
|
@@ -3,7 +3,7 @@ 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
|
interface IVersionable {
|
9
9
|
|
@@ -11,8 +11,8 @@ interface IVersionable {
|
|
11
11
|
Version version;
|
12
12
|
address implementation;
|
13
13
|
address activatedBy;
|
14
|
-
Blocknumber activatedIn;
|
15
14
|
Timestamp activatedAt;
|
15
|
+
Blocknumber activatedIn;
|
16
16
|
}
|
17
17
|
|
18
18
|
event LogVersionableActivated(Version version, address implementation, address activatedBy);
|
@@ -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
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
import {RoleId,
|
4
|
+
import {RoleId, RoleIdLib, PRODUCT_OWNER_ROLE_NAME, PRODUCT_OWNER_ROLE, POOL_OWNER_ROLE_NAME, POOL_OWNER_ROLE} from "../../contracts/types/RoleId.sol";
|
5
5
|
|
6
6
|
contract TestRoleId {
|
7
|
-
function getRole(string memory roleName) external pure returns (RoleId) { return toRoleId(roleName); }
|
7
|
+
function getRole(string memory roleName) external pure returns (RoleId) { return RoleIdLib.toRoleId(roleName); }
|
8
8
|
|
9
9
|
function getProductOwnerRoleName() external pure returns (string memory) { return PRODUCT_OWNER_ROLE_NAME(); }
|
10
10
|
function getProductOwnerRole() external pure returns (RoleId) { return PRODUCT_OWNER_ROLE(); }
|
@@ -2,8 +2,8 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
import {NftId} from "../../contracts/types/NftId.sol";
|
5
|
-
import {Version,
|
6
|
-
import {ServiceBase} from "../../contracts/instance/
|
5
|
+
import {Version, VersionLib} from "../../contracts/types/Version.sol";
|
6
|
+
import {ServiceBase} from "../../contracts/instance/base/ServiceBase.sol";
|
7
7
|
|
8
8
|
import {IVersionable} from "../../contracts/shared/IVersionable.sol";
|
9
9
|
import {Versionable} from "../../contracts/shared/Versionable.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
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {ObjectType} from "./ObjectType.sol";
|
5
|
+
|
6
|
+
type Key32 is bytes32;
|
7
|
+
type KeyId is bytes31;
|
8
|
+
|
9
|
+
// type bindings
|
10
|
+
using {
|
11
|
+
eqKey32 as ==,
|
12
|
+
neKey32 as !=,
|
13
|
+
Key32Lib.toKey
|
14
|
+
} for Key32 global;
|
15
|
+
|
16
|
+
// @dev Returns true iff keys are identical
|
17
|
+
function eqKey32(Key32 a, Key32 b) pure returns (bool isSame) {
|
18
|
+
return Key32.unwrap(a) == Key32.unwrap(b);
|
19
|
+
}
|
20
|
+
|
21
|
+
// @dev Returns true iff keys are different
|
22
|
+
function neKey32(Key32 a, Key32 b) pure returns (bool isDifferent) {
|
23
|
+
return Key32.unwrap(a) != Key32.unwrap(b);
|
24
|
+
}
|
25
|
+
|
26
|
+
library Key32Lib {
|
27
|
+
|
28
|
+
uint8 public constant TYPE_SHIFT = 31 * 8;
|
29
|
+
uint8 public constant ID_SHIFT = uint8(32 * 8 - TYPE_SHIFT);
|
30
|
+
bytes32 public constant TYPE_MASK = bytes32(bytes1(type(uint8).max)); // first byte in bytes32
|
31
|
+
bytes32 public constant ID_MASK = bytes32(~TYPE_MASK); // remaining bytes in bytes32
|
32
|
+
|
33
|
+
function toKey32(ObjectType objectType, KeyId id) public pure returns (Key32) {
|
34
|
+
uint256 uintObjectType = ObjectType.unwrap(objectType);
|
35
|
+
uint256 uintId = uint248(KeyId.unwrap(id));
|
36
|
+
uint256 uintKey = (uintObjectType << TYPE_SHIFT) + uintId;
|
37
|
+
return Key32.wrap(bytes32(uintKey));
|
38
|
+
}
|
39
|
+
|
40
|
+
function toKey(Key32 key) public pure returns (ObjectType objectType, KeyId id) {
|
41
|
+
bytes32 key32 = Key32.unwrap(key);
|
42
|
+
objectType = ObjectType.wrap(uint8(uint256(key32 & TYPE_MASK) >> TYPE_SHIFT));
|
43
|
+
id = KeyId.wrap(bytes31((key32 & ID_MASK) << ID_SHIFT));
|
44
|
+
}
|
45
|
+
}
|
@@ -1,6 +1,9 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
+
import {Key32, KeyId, Key32Lib} from "./Key32.sol";
|
5
|
+
import {ObjectType} from "./ObjectType.sol";
|
6
|
+
|
4
7
|
// uint96 allows for chain ids up to 13 digits
|
5
8
|
type NftId is uint96;
|
6
9
|
|
@@ -10,7 +13,9 @@ using {
|
|
10
13
|
neNftId as !=,
|
11
14
|
NftIdLib.toInt,
|
12
15
|
NftIdLib.gtz,
|
13
|
-
NftIdLib.eqz
|
16
|
+
NftIdLib.eqz,
|
17
|
+
NftIdLib.toKeyId,
|
18
|
+
NftIdLib.toKey32
|
14
19
|
} for NftId global;
|
15
20
|
|
16
21
|
// general pure free functions
|
@@ -54,4 +59,14 @@ library NftIdLib {
|
|
54
59
|
function eq(NftId a, NftId b) public pure returns (bool isSame) {
|
55
60
|
return eqNftId(a, b);
|
56
61
|
}
|
62
|
+
|
63
|
+
/// @dev Returns the key32 value for the specified nft id and object type.
|
64
|
+
function toKey32(NftId id, ObjectType objectType) public pure returns (Key32 key) {
|
65
|
+
return Key32Lib.toKey32(objectType, toKeyId(id));
|
66
|
+
}
|
67
|
+
|
68
|
+
/// @dev Returns the key id value for the specified nft id
|
69
|
+
function toKeyId(NftId id) public pure returns (KeyId keyId) {
|
70
|
+
return KeyId.wrap(bytes31(uint248(NftId.unwrap(id))));
|
71
|
+
}
|
57
72
|
}
|
@@ -15,15 +15,10 @@ function ORACLE_OWNER_ROLE_NAME() pure returns (string memory) { return "OracleO
|
|
15
15
|
function POOL_OWNER_ROLE_NAME() pure returns (string memory) { return "PoolOwnerRole"; }
|
16
16
|
function PRODUCT_OWNER_ROLE_NAME() pure returns (string memory) { return "ProductOwnerRole"; }
|
17
17
|
|
18
|
-
function DISTRIBUTOR_OWNER_ROLE() pure returns (RoleId) { return toRoleId("DistributorOwnerRole"); }
|
19
|
-
function ORACLE_OWNER_ROLE() pure returns (RoleId) { return toRoleId("OracleOwnerRole"); }
|
20
|
-
function POOL_OWNER_ROLE() pure returns (RoleId) { return toRoleId("PoolOwnerRole"); }
|
21
|
-
function PRODUCT_OWNER_ROLE() pure returns (RoleId) { return toRoleId("ProductOwnerRole"); }
|
22
|
-
|
23
|
-
// @dev Converts a role string into a role id.
|
24
|
-
function toRoleId(string memory role) pure returns (RoleId) {
|
25
|
-
return RoleId.wrap(bytes8(keccak256(abi.encode(role))));
|
26
|
-
}
|
18
|
+
function DISTRIBUTOR_OWNER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId("DistributorOwnerRole"); }
|
19
|
+
function ORACLE_OWNER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId("OracleOwnerRole"); }
|
20
|
+
function POOL_OWNER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId("PoolOwnerRole"); }
|
21
|
+
function PRODUCT_OWNER_ROLE() pure returns (RoleId) { return RoleIdLib.toRoleId("ProductOwnerRole"); }
|
27
22
|
|
28
23
|
// @dev Returns true iff role ids a and b are identical
|
29
24
|
function eqRoleId(RoleId a, RoleId b) pure returns (bool isSame) {
|
@@ -34,3 +29,10 @@ function eqRoleId(RoleId a, RoleId b) pure returns (bool isSame) {
|
|
34
29
|
function neRoleId(RoleId a, RoleId b) pure returns (bool isDifferent) {
|
35
30
|
return RoleId.unwrap(a) != RoleId.unwrap(b);
|
36
31
|
}
|
32
|
+
|
33
|
+
library RoleIdLib {
|
34
|
+
// @dev Converts a role string into a role id.
|
35
|
+
function toRoleId(string memory role) public pure returns (RoleId) {
|
36
|
+
return RoleId.wrap(bytes8(keccak256(abi.encode(role))));
|
37
|
+
}
|
38
|
+
}
|
@@ -5,7 +5,13 @@ pragma solidity ^0.8.19;
|
|
5
5
|
type StateId is uint8;
|
6
6
|
|
7
7
|
// type bindings
|
8
|
-
using {
|
8
|
+
using {
|
9
|
+
eqStateId as ==,
|
10
|
+
neStateId as !=,
|
11
|
+
StateIdLib.eqz,
|
12
|
+
StateIdLib.gtz,
|
13
|
+
StateIdLib.toInt
|
14
|
+
} for StateId global;
|
9
15
|
|
10
16
|
// general pure free functions
|
11
17
|
function APPLIED() pure returns (StateId) {
|
@@ -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