@etherisc/gif-next 0.0.2-ed4dd55 → 0.0.2-f824182-503
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +25 -0
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +35 -9
- package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +84 -8
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +34 -152
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +146 -13
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +148 -15
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +105 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +4 -0
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +105 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
- 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 +4 -0
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +59 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.json +124 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.json +74 -0
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.json +124 -0
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +4 -0
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +207 -0
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +714 -127
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +845 -129
- package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +31 -59
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +103 -6
- package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +34 -8
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +31 -59
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +50 -3
- package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.json +134 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.json +182 -0
- package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +4 -0
- package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +221 -0
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +44 -21
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +44 -21
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +23 -43
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +28 -35
- package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +21 -8
- package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +85 -14
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.json +10 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +490 -0
- package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +45 -0
- package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +4 -0
- package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +490 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +8 -8
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +20 -111
- package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.json +9 -9
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +66 -115
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +4 -0
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +174 -0
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +85 -3
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +4 -0
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +92 -0
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/StateId.sol/StateIdLib.json +92 -0
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +4 -0
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +174 -0
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +4 -0
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +453 -0
- package/contracts/components/Component.sol +39 -24
- package/contracts/components/IPool.sol +9 -3
- package/contracts/components/IProduct.sol +11 -6
- package/contracts/components/Pool.sol +37 -14
- package/contracts/components/Product.sol +48 -24
- package/contracts/experiment/errors/Require.sol +38 -0
- package/contracts/experiment/errors/Revert.sol +44 -0
- package/contracts/experiment/inheritance/A.sol +8 -11
- package/contracts/experiment/inheritance/B.sol +10 -5
- package/contracts/experiment/inheritance/C.sol +11 -5
- package/contracts/experiment/inheritance/IA.sol +2 -7
- package/contracts/experiment/inheritance/IB.sol +3 -2
- package/contracts/experiment/inheritance/IC.sol +4 -3
- package/contracts/experiment/statemachine/Dummy.sol +27 -0
- package/contracts/experiment/statemachine/ISM.sol +25 -0
- package/contracts/experiment/statemachine/README.md +112 -0
- package/contracts/experiment/statemachine/SM.sol +57 -0
- package/contracts/experiment/statemachine/SimpleStateMachine.sol +31 -0
- package/contracts/experiment/types/TypeA.sol +14 -9
- package/contracts/experiment/types/TypeB.sol +14 -9
- package/contracts/instance/IInstance.sol +8 -3
- package/contracts/instance/Instance.sol +24 -15
- package/contracts/instance/access/Access.sol +63 -116
- package/contracts/instance/access/IAccess.sol +28 -48
- package/contracts/instance/component/ComponentModule.sol +162 -147
- package/contracts/instance/component/IComponent.sol +41 -61
- package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
- package/contracts/instance/policy/IPolicy.sol +19 -35
- package/contracts/instance/policy/PolicyModule.sol +52 -44
- package/contracts/instance/pool/IPoolModule.sol +9 -26
- package/contracts/instance/pool/PoolModule.sol +43 -45
- package/contracts/instance/product/IProductService.sol +10 -19
- package/contracts/instance/product/ProductService.sol +86 -55
- package/contracts/instance/treasury/ITreasury.sol +91 -0
- package/contracts/instance/treasury/TokenHandler.sol +24 -0
- package/contracts/instance/treasury/TreasuryModule.sol +168 -0
- package/contracts/registry/ChainNft.sol +23 -61
- package/contracts/registry/IChainNft.sol +10 -7
- package/contracts/registry/IRegistry.sol +40 -41
- package/contracts/registry/Registry.sol +73 -67
- package/contracts/types/Blocknumber.sol +118 -0
- package/contracts/types/ChainId.sol +24 -10
- package/contracts/types/Fee.sol +32 -0
- package/contracts/types/NftId.sol +36 -10
- package/contracts/types/ObjectType.sol +107 -0
- package/contracts/types/StateId.sol +91 -0
- package/contracts/types/Timestamp.sol +102 -0
- package/contracts/types/UFixed.sol +206 -0
- package/package.json +10 -4
@@ -1,29 +1,52 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
+
import {ObjectType, POOL} from "../types/ObjectType.sol";
|
5
|
+
import {Fee} from "../types/Fee.sol";
|
4
6
|
import {IPoolComponent} from "./IPool.sol";
|
5
7
|
import {Component} from "./Component.sol";
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
IPoolComponent
|
11
|
-
{
|
9
|
+
contract Pool is Component, IPoolComponent {
|
10
|
+
Fee private _stakingFee;
|
11
|
+
Fee private _performanceFee;
|
12
12
|
|
13
13
|
constructor(
|
14
|
-
address registry,
|
15
|
-
address instance
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
address registry,
|
15
|
+
address instance,
|
16
|
+
address token,
|
17
|
+
Fee memory stakingFee,
|
18
|
+
Fee memory performanceFee
|
19
|
+
) Component(registry, instance, token) {
|
20
|
+
_stakingFee = stakingFee;
|
21
|
+
_performanceFee = performanceFee;
|
22
|
+
}
|
23
|
+
|
24
|
+
// from pool component
|
25
|
+
function getStakingFee()
|
26
|
+
external
|
27
|
+
view
|
28
|
+
override
|
29
|
+
returns (Fee memory stakingFee)
|
30
|
+
{
|
31
|
+
return _stakingFee;
|
32
|
+
}
|
33
|
+
|
34
|
+
function getPerformanceFee()
|
35
|
+
external
|
36
|
+
view
|
37
|
+
override
|
38
|
+
returns (Fee memory performanceFee)
|
39
|
+
{
|
40
|
+
return _performanceFee;
|
41
|
+
}
|
19
42
|
|
20
43
|
// from registerable
|
21
|
-
function getType() public
|
22
|
-
return
|
44
|
+
function getType() public pure override returns (ObjectType) {
|
45
|
+
return POOL();
|
23
46
|
}
|
24
47
|
|
25
48
|
// from registerable
|
26
|
-
function getData() external view override returns(bytes memory data) {
|
49
|
+
function getData() external view override returns (bytes memory data) {
|
27
50
|
return bytes(abi.encode(getInstance().getNftId()));
|
28
51
|
}
|
29
|
-
}
|
52
|
+
}
|
@@ -4,24 +4,30 @@ pragma solidity ^0.8.19;
|
|
4
4
|
import {IProductService} from "../instance/product/IProductService.sol";
|
5
5
|
import {Component} from "./Component.sol";
|
6
6
|
import {IProductComponent} from "./IProduct.sol";
|
7
|
+
import {NftId} from "../types/NftId.sol";
|
8
|
+
import {ObjectType, PRODUCT} from "../types/ObjectType.sol";
|
9
|
+
import {Fee} from "../types/Fee.sol";
|
10
|
+
import {Component} from "./Component.sol";
|
7
11
|
|
8
|
-
|
9
|
-
contract Product is
|
10
|
-
Component,
|
11
|
-
IProductComponent
|
12
|
-
{
|
12
|
+
contract Product is Component, IProductComponent {
|
13
13
|
IProductService private _productService;
|
14
14
|
address private _pool;
|
15
|
+
Fee private _policyFee;
|
16
|
+
Fee private _processingFee;
|
15
17
|
|
16
18
|
constructor(
|
17
|
-
address registry,
|
18
|
-
address instance,
|
19
|
-
address
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
address registry,
|
20
|
+
address instance,
|
21
|
+
address token,
|
22
|
+
address pool,
|
23
|
+
Fee memory policyFee,
|
24
|
+
Fee memory processingFee
|
25
|
+
) Component(registry, instance, token) {
|
26
|
+
// TODO add validation
|
23
27
|
_productService = _instance.getProductService();
|
24
28
|
_pool = pool;
|
29
|
+
_policyFee = policyFee;
|
30
|
+
_processingFee = processingFee;
|
25
31
|
}
|
26
32
|
|
27
33
|
function _createApplication(
|
@@ -29,11 +35,8 @@ contract Product is
|
|
29
35
|
uint256 sumInsuredAmount,
|
30
36
|
uint256 premiumAmount,
|
31
37
|
uint256 lifetime,
|
32
|
-
|
33
|
-
)
|
34
|
-
internal
|
35
|
-
returns(uint256 nftId)
|
36
|
-
{
|
38
|
+
NftId bundleNftId
|
39
|
+
) internal returns (NftId nftId) {
|
37
40
|
nftId = _productService.createApplication(
|
38
41
|
applicationOwner,
|
39
42
|
sumInsuredAmount,
|
@@ -43,23 +46,44 @@ contract Product is
|
|
43
46
|
);
|
44
47
|
}
|
45
48
|
|
46
|
-
function _underwrite(
|
47
|
-
internal
|
48
|
-
{
|
49
|
+
function _underwrite(NftId nftId) internal {
|
49
50
|
_productService.underwrite(nftId);
|
50
51
|
}
|
51
52
|
|
52
|
-
function
|
53
|
+
function _collectPremium(NftId nftId) internal {
|
54
|
+
_productService.collectPremium(nftId);
|
55
|
+
}
|
56
|
+
|
57
|
+
function getPoolNftId() external view override returns (NftId poolNftId) {
|
53
58
|
return _registry.getNftId(_pool);
|
54
59
|
}
|
55
60
|
|
61
|
+
// from product component
|
62
|
+
function getPolicyFee()
|
63
|
+
external
|
64
|
+
view
|
65
|
+
override
|
66
|
+
returns (Fee memory policyFee)
|
67
|
+
{
|
68
|
+
return _policyFee;
|
69
|
+
}
|
70
|
+
|
71
|
+
function getProcessingFee()
|
72
|
+
external
|
73
|
+
view
|
74
|
+
override
|
75
|
+
returns (Fee memory processingFee)
|
76
|
+
{
|
77
|
+
return _processingFee;
|
78
|
+
}
|
79
|
+
|
56
80
|
// from registerable
|
57
|
-
function getType() public
|
58
|
-
return
|
81
|
+
function getType() public pure override returns (ObjectType) {
|
82
|
+
return PRODUCT();
|
59
83
|
}
|
60
84
|
|
61
85
|
// from registerable
|
62
|
-
function getData() external view override returns(bytes memory data) {
|
86
|
+
function getData() external view override returns (bytes memory data) {
|
63
87
|
return bytes(abi.encode(getInstance().getNftId()));
|
64
88
|
}
|
65
|
-
}
|
89
|
+
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
contract Require {
|
5
|
+
error AsmallerThanB_S();
|
6
|
+
error AsmallerThanB_M(uint a);
|
7
|
+
error AsmallerThanB_L(uint a, uint b);
|
8
|
+
|
9
|
+
uint256 private _b;
|
10
|
+
|
11
|
+
constructor() {
|
12
|
+
_b = 42;
|
13
|
+
}
|
14
|
+
|
15
|
+
function isAlargerThanBRequire_S(
|
16
|
+
uint a
|
17
|
+
) external view returns (bool isLarger) {
|
18
|
+
require(a > _b, "ERROR:ABC-001");
|
19
|
+
|
20
|
+
return true;
|
21
|
+
}
|
22
|
+
|
23
|
+
function isAlargerThanBRequire_M(
|
24
|
+
uint a
|
25
|
+
) external view returns (bool isLarger) {
|
26
|
+
require(a > _b, "ERROR:ABC-002:A_IS_SMALLER");
|
27
|
+
|
28
|
+
return true;
|
29
|
+
}
|
30
|
+
|
31
|
+
function isAlargerThanBRequire_L(
|
32
|
+
uint a
|
33
|
+
) external view returns (bool isLarger) {
|
34
|
+
require(a > _b, "ERROR:ABC-003:A_IS_SMALLER_THAN_B");
|
35
|
+
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,44 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
contract Revert {
|
5
|
+
error AsmallerThanB_S();
|
6
|
+
error AsmallerThanB_M(uint a);
|
7
|
+
error AsmallerThanB_L(uint a, uint b);
|
8
|
+
|
9
|
+
uint256 private _b;
|
10
|
+
|
11
|
+
constructor() {
|
12
|
+
_b = 42;
|
13
|
+
}
|
14
|
+
|
15
|
+
function isAlargerThanBRevert_S(
|
16
|
+
uint a
|
17
|
+
) external view returns (bool isLarger) {
|
18
|
+
if (a <= _b) {
|
19
|
+
revert AsmallerThanB_S();
|
20
|
+
}
|
21
|
+
|
22
|
+
return true;
|
23
|
+
}
|
24
|
+
|
25
|
+
function isAlargerThanBRevert_M(
|
26
|
+
uint a
|
27
|
+
) external view returns (bool isLarger) {
|
28
|
+
if (a <= _b) {
|
29
|
+
revert AsmallerThanB_M(a);
|
30
|
+
}
|
31
|
+
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
|
35
|
+
function isAlargerThanBRevert_L(
|
36
|
+
uint a
|
37
|
+
) external view returns (bool isLarger) {
|
38
|
+
if (a <= _b) {
|
39
|
+
revert AsmallerThanB_L(a, _b);
|
40
|
+
}
|
41
|
+
|
42
|
+
return true;
|
43
|
+
}
|
44
|
+
}
|
@@ -35,22 +35,19 @@ a.setC(20);
|
|
35
35
|
*/
|
36
36
|
|
37
37
|
contract AShared is ISharedA {
|
38
|
-
|
39
38
|
uint256 private _x;
|
40
39
|
|
41
40
|
constructor() {
|
42
41
|
_x = 42;
|
43
42
|
}
|
44
43
|
|
45
|
-
function getA() external view override returns(uint256) {
|
46
|
-
|
47
|
-
}
|
48
|
-
|
49
|
-
contract A is
|
50
|
-
AShared,
|
51
|
-
B,
|
52
|
-
C,
|
53
|
-
IA
|
54
|
-
{
|
44
|
+
function getA() external view override returns (uint256) {
|
45
|
+
return _x;
|
46
|
+
}
|
55
47
|
|
48
|
+
function setA(uint256 newA) external override {
|
49
|
+
_x = newA;
|
50
|
+
}
|
56
51
|
}
|
52
|
+
|
53
|
+
contract A is AShared, B, C, IA {}
|
@@ -5,7 +5,6 @@ import {ISharedA} from "./IA.sol";
|
|
5
5
|
import {IB} from "./IB.sol";
|
6
6
|
|
7
7
|
abstract contract B is ISharedA, IB {
|
8
|
-
|
9
8
|
// names of private variables can be re-used in inheritance
|
10
9
|
uint256 private _x;
|
11
10
|
|
@@ -14,10 +13,16 @@ abstract contract B is ISharedA, IB {
|
|
14
13
|
}
|
15
14
|
|
16
15
|
// access own state
|
17
|
-
function getB() external view override returns(uint256) {
|
18
|
-
|
16
|
+
function getB() external view override returns (uint256) {
|
17
|
+
return _x;
|
18
|
+
}
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
function setB(uint256 newB) external override {
|
21
|
+
_x = newB;
|
22
|
+
}
|
22
23
|
|
24
|
+
// access state from parent contract A
|
25
|
+
function getAfromB() external view override returns (uint256) {
|
26
|
+
return this.getA();
|
27
|
+
}
|
23
28
|
}
|
@@ -6,7 +6,6 @@ import {IB} from "./IB.sol";
|
|
6
6
|
import {IC} from "./IC.sol";
|
7
7
|
|
8
8
|
abstract contract C is ISharedA, IC {
|
9
|
-
|
10
9
|
uint256 private _x;
|
11
10
|
|
12
11
|
constructor() {
|
@@ -14,14 +13,21 @@ abstract contract C is ISharedA, IC {
|
|
14
13
|
}
|
15
14
|
|
16
15
|
// access own state
|
17
|
-
function getC() external view override returns(uint256) {
|
18
|
-
|
16
|
+
function getC() external view override returns (uint256) {
|
17
|
+
return _x;
|
18
|
+
}
|
19
|
+
|
20
|
+
function setC(uint256 newC) external override {
|
21
|
+
_x = newC;
|
22
|
+
}
|
19
23
|
|
20
24
|
// access state from parent contract A
|
21
|
-
function getAfromC() external view override returns(uint256) {
|
25
|
+
function getAfromC() external view override returns (uint256) {
|
26
|
+
return this.getA();
|
27
|
+
}
|
22
28
|
|
23
29
|
// access state from other module B
|
24
|
-
function getBfromC() external view override returns(uint256) {
|
30
|
+
function getBfromC() external view override returns (uint256) {
|
25
31
|
IB b = IB(address(this));
|
26
32
|
return b.getB();
|
27
33
|
}
|
@@ -5,14 +5,9 @@ import {IB} from "./IB.sol";
|
|
5
5
|
import {IC} from "./IC.sol";
|
6
6
|
|
7
7
|
interface ISharedA {
|
8
|
+
function getA() external view returns (uint256);
|
8
9
|
|
9
|
-
function getA() external view returns(uint256);
|
10
10
|
function setA(uint256 newA) external;
|
11
11
|
}
|
12
12
|
|
13
|
-
interface IA is
|
14
|
-
ISharedA,
|
15
|
-
IB,
|
16
|
-
IC
|
17
|
-
{
|
18
|
-
}
|
13
|
+
interface IA is ISharedA, IB, IC {}
|
@@ -2,8 +2,9 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
interface IB {
|
5
|
+
function getAfromB() external view returns (uint256);
|
6
|
+
|
7
|
+
function getB() external view returns (uint256);
|
5
8
|
|
6
|
-
function getAfromB() external view returns(uint256);
|
7
|
-
function getB() external view returns(uint256);
|
8
9
|
function setB(uint256 newA) external;
|
9
10
|
}
|
@@ -2,10 +2,11 @@
|
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
4
|
interface IC {
|
5
|
+
function getAfromC() external view returns (uint256);
|
5
6
|
|
6
|
-
function
|
7
|
-
|
7
|
+
function getBfromC() external view returns (uint256);
|
8
|
+
|
9
|
+
function getC() external view returns (uint256);
|
8
10
|
|
9
|
-
function getC() external view returns(uint256);
|
10
11
|
function setC(uint256 newA) external;
|
11
12
|
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {ObjectType} from "../../types/ObjectType.sol";
|
5
|
+
import {StateId, toStateId, zeroStateId} from "../../types/StateId.sol";
|
6
|
+
|
7
|
+
contract LifeCycleModule {
|
8
|
+
mapping(ObjectType objectType => StateId initialState)
|
9
|
+
private _initialState;
|
10
|
+
|
11
|
+
mapping(ObjectType objectType => mapping(StateId stateFrom => mapping(StateId stateTo => bool isValid)))
|
12
|
+
private _isValidTransition;
|
13
|
+
|
14
|
+
function getInitialState(
|
15
|
+
ObjectType objectType
|
16
|
+
) external view returns (StateId) {
|
17
|
+
return _initialState[objectType];
|
18
|
+
}
|
19
|
+
|
20
|
+
function isValidTransition(
|
21
|
+
ObjectType objectType,
|
22
|
+
StateId fromId,
|
23
|
+
StateId toId
|
24
|
+
) external view returns (bool) {
|
25
|
+
return _isValidTransition[objectType][fromId][toId];
|
26
|
+
}
|
27
|
+
}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {StateId} from "../../types/StateId.sol";
|
5
|
+
|
6
|
+
interface ISMEE {
|
7
|
+
error ErrorInitialStateUndefined();
|
8
|
+
error ErrorStartStateUndefined();
|
9
|
+
error ErrorNextStateUndefined();
|
10
|
+
error ErrorStateChangeInvalid(StateId currentStateId, StateId newStateId);
|
11
|
+
|
12
|
+
event LogInitialStateSet(StateId initialStateId);
|
13
|
+
event LogStateChanged(StateId oldStateId, StateId newStateId);
|
14
|
+
}
|
15
|
+
|
16
|
+
interface ISM is ISMEE {
|
17
|
+
function changeToState(StateId newStateId) external;
|
18
|
+
|
19
|
+
function isValidTransition(
|
20
|
+
StateId currentStateId,
|
21
|
+
StateId newStateId
|
22
|
+
) external view returns (bool isValid);
|
23
|
+
|
24
|
+
function getState() external view returns (StateId currentStateId);
|
25
|
+
}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# State Machines
|
2
|
+
|
3
|
+
Most GIF objects have a life cycle defined by a state machine.
|
4
|
+
|
5
|
+
For each object type the set of possible states is defined together with its initial state and the set of valid state transitions.
|
6
|
+
|
7
|
+
## Object Types without States
|
8
|
+
|
9
|
+
* Protocol
|
10
|
+
* Chains
|
11
|
+
* Registries (both chain and main registry)
|
12
|
+
|
13
|
+
## Object Types with States
|
14
|
+
|
15
|
+
* Tokens
|
16
|
+
* Instances
|
17
|
+
* Products
|
18
|
+
* Oracles
|
19
|
+
* Pools
|
20
|
+
* Bundles
|
21
|
+
* Policies
|
22
|
+
* Claim (non-NFT)
|
23
|
+
* Payout (non-NFT)
|
24
|
+
|
25
|
+
### Simple State Machine
|
26
|
+
|
27
|
+
Valid states
|
28
|
+
|
29
|
+
* Active (initial state)
|
30
|
+
* Paused
|
31
|
+
* Archived (final state)
|
32
|
+
|
33
|
+
Valid state transitions:
|
34
|
+
|
35
|
+
* Active -> Paused
|
36
|
+
* Paused -> Active
|
37
|
+
* Paused -> Archived
|
38
|
+
|
39
|
+
|
40
|
+
Candidate object types for simple state machine
|
41
|
+
|
42
|
+
* Token
|
43
|
+
* Instance
|
44
|
+
* Product
|
45
|
+
* Oracle
|
46
|
+
* Pool
|
47
|
+
|
48
|
+
To discuss:
|
49
|
+
|
50
|
+
* Archived is final state
|
51
|
+
* What mechanism should exist to revert an unintended transition to 'Archived' state. Should there be such a mechanism?
|
52
|
+
* What mechanism should exist when the NFT of such an object is burned prematurely. Should there be such a mechanism
|
53
|
+
|
54
|
+
### Bundle State Machine
|
55
|
+
|
56
|
+
Valid states
|
57
|
+
|
58
|
+
* Active (initial state)
|
59
|
+
* Paused
|
60
|
+
* Expired (implicit state)
|
61
|
+
* Closed (final state)
|
62
|
+
|
63
|
+
Expired is not an explicit state.
|
64
|
+
A bundle is expired for block.timestamp >= expiredAt
|
65
|
+
|
66
|
+
### Policy State Machine
|
67
|
+
|
68
|
+
Valid states
|
69
|
+
|
70
|
+
* Applied (initial state)
|
71
|
+
* Revoked (final state)
|
72
|
+
* Declined (final state)
|
73
|
+
* Active
|
74
|
+
* Expired (implicit state)
|
75
|
+
* Closed (final state)
|
76
|
+
|
77
|
+
Expired is not an explicit state.
|
78
|
+
A policy is expired for block.timestamp >= expiredAt
|
79
|
+
|
80
|
+
To discuss:
|
81
|
+
|
82
|
+
* Should 'Closed' be less explicit using a closedAt state variable?
|
83
|
+
* Or even more lighweight? ie. block.timestamp >= expiredAt and no open claims
|
84
|
+
|
85
|
+
Valid state transitions:
|
86
|
+
|
87
|
+
* Applied -> Revoked
|
88
|
+
* Applied -> Declined
|
89
|
+
* Applied -> Active
|
90
|
+
* Active -> Closed (needs to be expired)
|
91
|
+
|
92
|
+
### Claim State Machine
|
93
|
+
|
94
|
+
Valid states
|
95
|
+
* Applied (initial state)
|
96
|
+
* Confirmed
|
97
|
+
* Declined (final state)
|
98
|
+
* Closed (final state)
|
99
|
+
|
100
|
+
Valid state transitions:
|
101
|
+
* Applied -> Confirmed
|
102
|
+
* Applied -> Declined
|
103
|
+
* Confirmed -> Closed
|
104
|
+
|
105
|
+
### Payout State Machine
|
106
|
+
|
107
|
+
Valid states
|
108
|
+
* Expected
|
109
|
+
* PaidOut
|
110
|
+
|
111
|
+
Valid state transitions:
|
112
|
+
* Expected -> PaidOut
|
@@ -0,0 +1,57 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {StateId, toStateId, zeroStateId} from "../../types/StateId.sol";
|
5
|
+
import {ISM} from "./ISM.sol";
|
6
|
+
|
7
|
+
contract SM is ISM {
|
8
|
+
mapping(StateId currentState => mapping(StateId newState => bool isValid))
|
9
|
+
private _isValidTransition;
|
10
|
+
|
11
|
+
StateId internal _state;
|
12
|
+
|
13
|
+
function setInitialState(StateId initialStateId) internal {
|
14
|
+
if (initialStateId == zeroStateId()) {
|
15
|
+
revert ErrorInitialStateUndefined();
|
16
|
+
}
|
17
|
+
|
18
|
+
_state = initialStateId;
|
19
|
+
}
|
20
|
+
|
21
|
+
function addTransition(
|
22
|
+
StateId currentStateId,
|
23
|
+
StateId nextStateId
|
24
|
+
) internal {
|
25
|
+
if (currentStateId == zeroStateId()) {
|
26
|
+
revert ErrorStartStateUndefined();
|
27
|
+
}
|
28
|
+
|
29
|
+
if (nextStateId == zeroStateId()) {
|
30
|
+
revert ErrorNextStateUndefined();
|
31
|
+
}
|
32
|
+
|
33
|
+
_isValidTransition[currentStateId][nextStateId] = true;
|
34
|
+
}
|
35
|
+
|
36
|
+
function changeToState(StateId newStateId) external override {
|
37
|
+
if (!_isValidTransition[_state][newStateId]) {
|
38
|
+
revert ErrorStateChangeInvalid(_state, newStateId);
|
39
|
+
}
|
40
|
+
|
41
|
+
StateId stateOld = _state;
|
42
|
+
_state = newStateId;
|
43
|
+
|
44
|
+
emit LogStateChanged(stateOld, _state);
|
45
|
+
}
|
46
|
+
|
47
|
+
function isValidTransition(
|
48
|
+
StateId currentStateId,
|
49
|
+
StateId newStateId
|
50
|
+
) external view override returns (bool isValid) {
|
51
|
+
return _isValidTransition[currentStateId][newStateId];
|
52
|
+
}
|
53
|
+
|
54
|
+
function getState() external view override returns (StateId state) {
|
55
|
+
return _state;
|
56
|
+
}
|
57
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {StateId, toStateId} from "../../types/StateId.sol";
|
5
|
+
import {SM} from "./SM.sol";
|
6
|
+
|
7
|
+
contract SimpleStateMachine is SM {
|
8
|
+
uint8 public constant STATE_ACTIVE = 10;
|
9
|
+
uint8 public constant STATE_PAUSED = 20;
|
10
|
+
uint8 public constant STATE_ARCHIVED = 30;
|
11
|
+
|
12
|
+
constructor() {
|
13
|
+
addTransition(ACTIVE(), PAUSED());
|
14
|
+
addTransition(PAUSED(), ACTIVE());
|
15
|
+
addTransition(PAUSED(), ARCHIVED());
|
16
|
+
|
17
|
+
setInitialState(ACTIVE());
|
18
|
+
}
|
19
|
+
|
20
|
+
function ACTIVE() public pure returns (StateId stateId) {
|
21
|
+
return toStateId(STATE_ACTIVE);
|
22
|
+
}
|
23
|
+
|
24
|
+
function PAUSED() public pure returns (StateId stateId) {
|
25
|
+
return toStateId(STATE_PAUSED);
|
26
|
+
}
|
27
|
+
|
28
|
+
function ARCHIVED() public pure returns (StateId stateId) {
|
29
|
+
return toStateId(STATE_ARCHIVED);
|
30
|
+
}
|
31
|
+
}
|
@@ -23,20 +23,25 @@ a.toInt() == x.toInt() // -> no error
|
|
23
23
|
type TypeA is uint248;
|
24
24
|
|
25
25
|
// type bindings
|
26
|
-
using {
|
27
|
-
eqTypeA as ==,
|
28
|
-
neTypeA as !=,
|
29
|
-
TypeALib.toInt
|
30
|
-
} for TypeA global;
|
26
|
+
using {eqTypeA as ==, neTypeA as !=, TypeALib.toInt} for TypeA global;
|
31
27
|
|
32
28
|
// general pure free functions
|
33
|
-
function toTypeA(uint256 typeA) pure returns(TypeA) {
|
29
|
+
function toTypeA(uint256 typeA) pure returns (TypeA) {
|
30
|
+
return TypeA.wrap(uint248(typeA));
|
31
|
+
}
|
34
32
|
|
35
33
|
// pure free functions for operators
|
36
|
-
function eqTypeA(TypeA a, TypeA b) pure returns(bool isSame) {
|
37
|
-
|
34
|
+
function eqTypeA(TypeA a, TypeA b) pure returns (bool isSame) {
|
35
|
+
return TypeA.unwrap(a) == TypeA.unwrap(b);
|
36
|
+
}
|
37
|
+
|
38
|
+
function neTypeA(TypeA a, TypeA b) pure returns (bool isDifferent) {
|
39
|
+
return TypeA.unwrap(a) != TypeA.unwrap(b);
|
40
|
+
}
|
38
41
|
|
39
42
|
// library functions that operate on user defined type
|
40
43
|
library TypeALib {
|
41
|
-
function toInt(TypeA typeA) internal pure returns(uint256) {
|
44
|
+
function toInt(TypeA typeA) internal pure returns (uint256) {
|
45
|
+
return uint256(TypeA.unwrap(typeA));
|
46
|
+
}
|
42
47
|
}
|