@etherisc/gif-next 0.0.2-c40f9a5 → 0.0.2-c6846dc-026
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -0
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +28 -2
- 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 +78 -2
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +32 -150
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +121 -6
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +121 -6
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
- 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 +686 -99
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +757 -99
- 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 +14 -42
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +65 -10
- 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 +28 -2
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +12 -40
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +47 -0
- 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 +26 -3
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +26 -3
- 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 +15 -35
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +22 -29
- 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 +13 -0
- 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 +41 -12
- 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 +2 -2
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +4 -95
- 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 +2 -2
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +14 -105
- 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 +1 -1
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
- 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 +2 -2
- 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 +1 -1
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +2 -2
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +2 -2
- package/contracts/components/Component.sol +38 -23
- package/contracts/components/IPool.sol +9 -3
- package/contracts/components/IProduct.sol +10 -6
- package/contracts/components/Pool.sol +37 -14
- package/contracts/components/Product.sol +46 -23
- package/contracts/experiment/errors/Require.sol +10 -5
- package/contracts/experiment/errors/Revert.sol +13 -8
- 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 +22 -14
- package/contracts/instance/access/Access.sol +63 -116
- package/contracts/instance/access/IAccess.sol +28 -48
- package/contracts/instance/component/ComponentModule.sol +144 -118
- package/contracts/instance/component/IComponent.sol +39 -60
- package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
- package/contracts/instance/policy/IPolicy.sol +16 -32
- package/contracts/instance/policy/PolicyModule.sol +47 -40
- package/contracts/instance/pool/IPoolModule.sol +7 -25
- package/contracts/instance/pool/PoolModule.sol +40 -45
- package/contracts/instance/product/IProductService.sol +6 -16
- package/contracts/instance/product/ProductService.sol +76 -48
- 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 +35 -38
- package/contracts/registry/Registry.sol +57 -57
- package/contracts/types/Blocknumber.sol +76 -18
- package/contracts/types/ChainId.sol +18 -10
- package/contracts/types/Fee.sol +32 -0
- package/contracts/types/NftId.sol +29 -13
- package/contracts/types/ObjectType.sol +107 -0
- package/contracts/types/StateId.sol +91 -0
- package/contracts/types/Timestamp.sol +63 -16
- package/contracts/types/UFixed.sol +59 -64
- package/package.json +12 -5
@@ -3,67 +3,59 @@ pragma solidity ^0.8.19;
|
|
3
3
|
|
4
4
|
import {IChainNft} from "./IChainNft.sol";
|
5
5
|
import {IRegistry, IRegistryLinked, IRegisterable} from "./IRegistry.sol";
|
6
|
-
import {NftId, toNftId} from "../types/NftId.sol";
|
7
|
-
import {
|
6
|
+
import {NftId, toNftId, NftIdLib} from "../types/NftId.sol";
|
7
|
+
import {ObjectType, INSTANCE, POLICY, BUNDLE} from "../types/ObjectType.sol";
|
8
8
|
|
9
9
|
contract RegistryLinked is IRegistryLinked {
|
10
|
-
|
11
10
|
IRegistry internal _registry;
|
12
|
-
|
11
|
+
|
13
12
|
constructor(address registry) {
|
14
13
|
_registry = IRegistry(registry);
|
15
14
|
}
|
16
15
|
|
17
|
-
function getRegistry() external view override returns(IRegistry registry) {
|
16
|
+
function getRegistry() external view override returns (IRegistry registry) {
|
18
17
|
return _registry;
|
19
18
|
}
|
20
|
-
|
21
19
|
}
|
22
20
|
|
23
|
-
|
24
|
-
abstract contract Registerable is
|
25
|
-
RegistryLinked,
|
26
|
-
IRegisterable
|
27
|
-
{
|
21
|
+
abstract contract Registerable is RegistryLinked, IRegisterable {
|
28
22
|
using NftIdLib for NftId;
|
29
23
|
|
30
24
|
address private _initialOwner;
|
31
|
-
|
32
|
-
constructor(address registry)
|
33
|
-
RegistryLinked(registry)
|
34
|
-
{
|
25
|
+
|
26
|
+
constructor(address registry) RegistryLinked(registry) {
|
35
27
|
_initialOwner = msg.sender;
|
36
28
|
}
|
37
29
|
|
38
30
|
// getType, getData and register need to be implemented by concrete contract
|
39
31
|
|
40
|
-
function isRegisterable() external pure override returns(bool) {
|
32
|
+
function isRegisterable() external pure override returns (bool) {
|
41
33
|
return true;
|
42
34
|
}
|
43
35
|
|
44
|
-
function getInitialOwner() public view override returns(address deployer) {
|
36
|
+
function getInitialOwner() public view override returns (address deployer) {
|
45
37
|
return _initialOwner;
|
46
38
|
}
|
47
39
|
|
48
|
-
function isRegistered() public view override returns(bool) {
|
40
|
+
function isRegistered() public view override returns (bool) {
|
49
41
|
NftId nftId = _registry.getNftId(address(this));
|
50
42
|
return nftId.gtz();
|
51
43
|
}
|
52
44
|
|
53
|
-
function getNftId() public view override returns(NftId nftId) {
|
45
|
+
function getNftId() public view override returns (NftId nftId) {
|
54
46
|
return _registry.getNftId(address(this));
|
55
47
|
}
|
56
48
|
|
57
|
-
function getOwner() public view override returns(address owner) {
|
49
|
+
function getOwner() public view override returns (address owner) {
|
58
50
|
NftId id = _registry.getNftId(address(this));
|
59
51
|
owner = _registry.getOwner(id);
|
60
52
|
return owner != address(0) ? owner : _initialOwner;
|
61
53
|
}
|
62
|
-
|
63
54
|
}
|
64
55
|
|
65
56
|
contract Registry is IRegistry {
|
66
57
|
using NftIdLib for NftId;
|
58
|
+
|
67
59
|
string public constant EMPTY_URI = "";
|
68
60
|
|
69
61
|
mapping(NftId nftId => RegistryInfo info) private _info;
|
@@ -73,37 +65,43 @@ contract Registry is IRegistry {
|
|
73
65
|
IChainNft private _chainNft;
|
74
66
|
|
75
67
|
function initialize(address chainNft) external {
|
76
|
-
require(
|
68
|
+
require(
|
69
|
+
address(_chainNft) == address(0),
|
70
|
+
"ERROR:REG-001:ALREADY_INITIALIZED"
|
71
|
+
);
|
77
72
|
_chainNft = IChainNft(chainNft);
|
78
73
|
}
|
79
74
|
|
80
|
-
function
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
function register(address objectAddress) external override returns(NftId nftId) {
|
89
|
-
require(_nftIdByAddress[objectAddress].eqz(), "ERROR:REG-002:ALREADY_REGISTERED");
|
75
|
+
function register(
|
76
|
+
address objectAddress
|
77
|
+
) external override returns (NftId nftId) {
|
78
|
+
require(
|
79
|
+
_nftIdByAddress[objectAddress].eqz(),
|
80
|
+
"ERROR:REG-002:ALREADY_REGISTERED"
|
81
|
+
);
|
90
82
|
|
91
83
|
IRegisterable registerable = IRegisterable(objectAddress);
|
92
|
-
require(
|
84
|
+
require(
|
85
|
+
registerable.isRegisterable(),
|
86
|
+
"ERROR:REG-003:NOT_REGISTERABLE"
|
87
|
+
);
|
93
88
|
|
94
89
|
// check parent exists (for objects not instances)
|
95
|
-
if(registerable.getType() != INSTANCE()) {
|
96
|
-
RegistryInfo memory parentInfo = _info[
|
90
|
+
if (registerable.getType() != INSTANCE()) {
|
91
|
+
RegistryInfo memory parentInfo = _info[
|
92
|
+
registerable.getParentNftId()
|
93
|
+
];
|
97
94
|
require(parentInfo.nftId.gtz(), "ERROR:REG-004:PARENT_NOT_FOUND");
|
98
95
|
// check validity of parent relation, valid relations are
|
99
96
|
// policy -> product, bundle -> pool, product -> instance, pool -> instance
|
100
97
|
}
|
101
98
|
|
102
99
|
uint256 mintedTokenId = _chainNft.mint(
|
103
|
-
registerable.getInitialOwner(),
|
104
|
-
EMPTY_URI
|
100
|
+
registerable.getInitialOwner(),
|
101
|
+
EMPTY_URI
|
102
|
+
);
|
105
103
|
nftId = toNftId(mintedTokenId);
|
106
|
-
|
104
|
+
|
107
105
|
RegistryInfo memory info = RegistryInfo(
|
108
106
|
nftId,
|
109
107
|
registerable.getParentNftId(),
|
@@ -118,25 +116,25 @@ contract Registry is IRegistry {
|
|
118
116
|
// add logging
|
119
117
|
}
|
120
118
|
|
121
|
-
|
122
119
|
function registerObjectForInstance(
|
123
120
|
NftId parentNftId,
|
124
|
-
|
121
|
+
ObjectType objectType,
|
125
122
|
address initialOwner
|
126
123
|
)
|
127
|
-
external
|
124
|
+
external
|
128
125
|
override
|
129
|
-
|
130
|
-
|
126
|
+
returns (
|
127
|
+
// TODO add onlyRegisteredInstance
|
128
|
+
NftId nftId
|
129
|
+
)
|
131
130
|
{
|
132
131
|
// TODO add more validation
|
133
132
|
require(
|
134
133
|
objectType == POLICY() || objectType == BUNDLE(),
|
135
|
-
"ERROR:REG-005:TYPE_INVALID"
|
134
|
+
"ERROR:REG-005:TYPE_INVALID"
|
135
|
+
);
|
136
136
|
|
137
|
-
uint256 mintedTokenId = _chainNft.mint(
|
138
|
-
initialOwner,
|
139
|
-
EMPTY_URI);
|
137
|
+
uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
|
140
138
|
nftId = toNftId(mintedTokenId);
|
141
139
|
|
142
140
|
RegistryInfo memory info = RegistryInfo(
|
@@ -152,31 +150,33 @@ contract Registry is IRegistry {
|
|
152
150
|
// add logging
|
153
151
|
}
|
154
152
|
|
155
|
-
|
156
|
-
function getObjectCount() external view override returns(uint256) {
|
153
|
+
function getObjectCount() external view override returns (uint256) {
|
157
154
|
return _chainNft.totalSupply();
|
158
155
|
}
|
159
156
|
|
160
|
-
|
161
|
-
|
157
|
+
function getNftId(
|
158
|
+
address object
|
159
|
+
) external view override returns (NftId id) {
|
162
160
|
return _nftIdByAddress[object];
|
163
161
|
}
|
164
162
|
|
165
|
-
|
166
|
-
|
163
|
+
function isRegistered(
|
164
|
+
address object
|
165
|
+
) external view override returns (bool) {
|
167
166
|
return _nftIdByAddress[object].gtz();
|
168
167
|
}
|
169
168
|
|
170
|
-
|
171
|
-
|
169
|
+
function getInfo(
|
170
|
+
NftId nftId
|
171
|
+
) external view override returns (RegistryInfo memory info) {
|
172
172
|
return _info[nftId];
|
173
173
|
}
|
174
174
|
|
175
|
-
function getOwner(NftId nftId) external view override returns(address) {
|
175
|
+
function getOwner(NftId nftId) external view override returns (address) {
|
176
176
|
return _chainNft.ownerOf(nftId.toInt());
|
177
177
|
}
|
178
178
|
|
179
|
-
function getNftAddress() external view override returns(address nft) {
|
179
|
+
function getNftAddress() external view override returns (address nft) {
|
180
180
|
return address(_chainNft);
|
181
181
|
}
|
182
182
|
}
|
@@ -14,47 +14,105 @@ using {
|
|
14
14
|
} for Blocknumber global;
|
15
15
|
|
16
16
|
/// @dev return true if Blocknumber a is greater than Blocknumber b
|
17
|
-
function gtBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) {
|
17
|
+
function gtBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
18
|
+
return Blocknumber.unwrap(a) > Blocknumber.unwrap(b);
|
19
|
+
}
|
20
|
+
|
18
21
|
/// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
|
19
|
-
function gteBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) {
|
22
|
+
function gteBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
23
|
+
return Blocknumber.unwrap(a) >= Blocknumber.unwrap(b);
|
24
|
+
}
|
20
25
|
|
21
26
|
/// @dev return true if Blocknumber a is less than Blocknumber b
|
22
|
-
function ltBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) {
|
27
|
+
function ltBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
28
|
+
return Blocknumber.unwrap(a) < Blocknumber.unwrap(b);
|
29
|
+
}
|
30
|
+
|
23
31
|
/// @dev return true if Blocknumber a is less than or equal to Blocknumber b
|
24
|
-
function lteBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) {
|
32
|
+
function lteBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
33
|
+
return Blocknumber.unwrap(a) <= Blocknumber.unwrap(b);
|
34
|
+
}
|
25
35
|
|
26
36
|
/// @dev return true if Blocknumber a is equal to Blocknumber b
|
27
|
-
function eqBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) {
|
37
|
+
function eqBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
38
|
+
return Blocknumber.unwrap(a) == Blocknumber.unwrap(b);
|
39
|
+
}
|
40
|
+
|
28
41
|
/// @dev return true if Blocknumber a is not equal to Blocknumber b
|
29
|
-
function neBlocknumber(Blocknumber a, Blocknumber b) pure returns(bool) {
|
42
|
+
function neBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
43
|
+
return Blocknumber.unwrap(a) != Blocknumber.unwrap(b);
|
44
|
+
}
|
30
45
|
|
31
46
|
/// @dev Converts the uint256 to a Blocknumber.
|
32
|
-
function toBlocknumber(uint256 blocknum) pure returns(Blocknumber) {
|
47
|
+
function toBlocknumber(uint256 blocknum) pure returns (Blocknumber) {
|
48
|
+
return Blocknumber.wrap(uint32(blocknum));
|
49
|
+
}
|
33
50
|
|
34
|
-
function blockBlocknumber() view returns(Blocknumber) {
|
51
|
+
function blockBlocknumber() view returns (Blocknumber) {
|
52
|
+
return toBlocknumber(block.number);
|
53
|
+
}
|
35
54
|
|
36
55
|
/// @dev Return the Blocknumber zero (0)
|
37
|
-
function zeroBlocknumber() pure returns(Blocknumber) {
|
56
|
+
function zeroBlocknumber() pure returns (Blocknumber) {
|
57
|
+
return toBlocknumber(0);
|
58
|
+
}
|
38
59
|
|
39
60
|
/// @dev Return the current block number
|
40
|
-
function blockNumber() view returns(Blocknumber) {
|
61
|
+
function blockNumber() view returns (Blocknumber) {
|
62
|
+
return toBlocknumber(block.number);
|
63
|
+
}
|
41
64
|
|
42
65
|
library BlocknumberLib {
|
43
66
|
/// @dev return true if Blocknumber a is greater than Blocknumber b
|
44
|
-
function gt(
|
67
|
+
function gt(
|
68
|
+
Blocknumber a,
|
69
|
+
Blocknumber b
|
70
|
+
) public pure returns (bool isAfter) {
|
71
|
+
return gtBlocknumber(a, b);
|
72
|
+
}
|
73
|
+
|
45
74
|
/// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
|
46
|
-
function gte(
|
47
|
-
|
75
|
+
function gte(
|
76
|
+
Blocknumber a,
|
77
|
+
Blocknumber b
|
78
|
+
) public pure returns (bool isAfterOrSame) {
|
79
|
+
return gteBlocknumber(a, b);
|
80
|
+
}
|
81
|
+
|
48
82
|
/// @dev return true if Blocknumber a is less than Blocknumber b
|
49
|
-
function lt(
|
83
|
+
function lt(
|
84
|
+
Blocknumber a,
|
85
|
+
Blocknumber b
|
86
|
+
) public pure returns (bool isBefore) {
|
87
|
+
return ltBlocknumber(a, b);
|
88
|
+
}
|
89
|
+
|
50
90
|
/// @dev return true if Blocknumber a is less than or equal to Blocknumber b
|
51
|
-
function lte(
|
91
|
+
function lte(
|
92
|
+
Blocknumber a,
|
93
|
+
Blocknumber b
|
94
|
+
) public pure returns (bool isBeforeOrSame) {
|
95
|
+
return lteBlocknumber(a, b);
|
96
|
+
}
|
52
97
|
|
53
98
|
/// @dev return true if Blocknumber a is equal to Blocknumber b
|
54
|
-
function eq(
|
99
|
+
function eq(
|
100
|
+
Blocknumber a,
|
101
|
+
Blocknumber b
|
102
|
+
) public pure returns (bool isSame) {
|
103
|
+
return eqBlocknumber(a, b);
|
104
|
+
}
|
105
|
+
|
55
106
|
/// @dev return true if Blocknumber a is not equal to Blocknumber b
|
56
|
-
function ne(
|
107
|
+
function ne(
|
108
|
+
Blocknumber a,
|
109
|
+
Blocknumber b
|
110
|
+
) public pure returns (bool isDifferent) {
|
111
|
+
return neBlocknumber(a, b);
|
112
|
+
}
|
57
113
|
|
58
114
|
/// @dev converts the Blocknumber to a uint256
|
59
|
-
function toInt(Blocknumber blocknumber) public pure returns(uint256) {
|
115
|
+
function toInt(Blocknumber blocknumber) public pure returns (uint256) {
|
116
|
+
return uint256(uint32(Blocknumber.unwrap(blocknumber)));
|
117
|
+
}
|
60
118
|
}
|
@@ -5,26 +5,34 @@ pragma solidity ^0.8.19;
|
|
5
5
|
type ChainId is bytes5;
|
6
6
|
|
7
7
|
// type bindings
|
8
|
-
using {
|
9
|
-
eqChainId as ==,
|
10
|
-
neChainId as !=,
|
11
|
-
ChainIdLib.toInt
|
12
|
-
} for ChainId global;
|
8
|
+
using {eqChainId as ==, neChainId as !=, ChainIdLib.toInt} for ChainId global;
|
13
9
|
|
14
10
|
// general pure free functions
|
15
11
|
/// @dev Converts the uint256 to a ChainId.
|
16
|
-
function toChainId(uint256 chainId) pure returns(ChainId) {
|
12
|
+
function toChainId(uint256 chainId) pure returns (ChainId) {
|
13
|
+
return ChainId.wrap(bytes5(uint40(chainId)));
|
14
|
+
}
|
15
|
+
|
17
16
|
/// @dev Return the ChainId for the chain the contract is deployed to
|
18
|
-
function thisChainId() view returns(ChainId) {
|
17
|
+
function thisChainId() view returns (ChainId) {
|
18
|
+
return toChainId(block.chainid);
|
19
|
+
}
|
19
20
|
|
20
21
|
// pure free functions for operators
|
21
22
|
/// @dev Returns true if the values are equal (==).
|
22
|
-
function eqChainId(ChainId a, ChainId b) pure returns(bool isSame) {
|
23
|
+
function eqChainId(ChainId a, ChainId b) pure returns (bool isSame) {
|
24
|
+
return ChainId.unwrap(a) == ChainId.unwrap(b);
|
25
|
+
}
|
26
|
+
|
23
27
|
/// @dev Returns true if the values are not equal (!=).
|
24
|
-
function neChainId(ChainId a, ChainId b) pure returns(bool isDifferent) {
|
28
|
+
function neChainId(ChainId a, ChainId b) pure returns (bool isDifferent) {
|
29
|
+
return ChainId.unwrap(a) != ChainId.unwrap(b);
|
30
|
+
}
|
25
31
|
|
26
32
|
// library functions that operate on user defined type
|
27
33
|
library ChainIdLib {
|
28
34
|
/// @dev Converts the ChainId to a uint256.
|
29
|
-
function toInt(ChainId chainId) internal pure returns(uint256) {
|
35
|
+
function toInt(ChainId chainId) internal pure returns (uint256) {
|
36
|
+
return uint256(uint40(ChainId.unwrap(chainId)));
|
37
|
+
}
|
30
38
|
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {UFixed} from "./UFixed.sol";
|
5
|
+
|
6
|
+
struct Fee {
|
7
|
+
UFixed fractionalFee;
|
8
|
+
uint256 fixedFee;
|
9
|
+
}
|
10
|
+
|
11
|
+
// general pure free functions
|
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
|
+
}
|
19
|
+
|
20
|
+
/// @dev Return the NftId zero (0)
|
21
|
+
function zeroFee() pure returns (Fee memory fee) {
|
22
|
+
return Fee(UFixed.wrap(0), 0);
|
23
|
+
}
|
24
|
+
|
25
|
+
// pure free functions for operators
|
26
|
+
function feeIsSame(Fee memory a, Fee memory b) pure returns (bool isSame) {
|
27
|
+
return a.fixedFee == b.fixedFee && a.fractionalFee == b.fractionalFee;
|
28
|
+
}
|
29
|
+
|
30
|
+
function feeIsZero(Fee memory fee) pure returns (bool) {
|
31
|
+
return fee.fixedFee == 0 && UFixed.unwrap(fee.fractionalFee) == 0;
|
32
|
+
}
|
@@ -5,31 +5,47 @@ pragma solidity ^0.8.19;
|
|
5
5
|
type NftId is uint96;
|
6
6
|
|
7
7
|
// type bindings
|
8
|
-
using {
|
9
|
-
eqNftId as ==,
|
10
|
-
neNftId as !=,
|
11
|
-
NftIdLib.toInt
|
12
|
-
} for NftId global;
|
8
|
+
using {eqNftId as ==, neNftId as !=, NftIdLib.toInt} for NftId global;
|
13
9
|
|
14
10
|
// general pure free functions
|
15
11
|
/// @dev Converts the uint256 to a NftId.
|
16
|
-
function toNftId(uint256 id) pure returns(NftId) {
|
12
|
+
function toNftId(uint256 id) pure returns (NftId) {
|
13
|
+
return NftId.wrap(uint96(id));
|
14
|
+
}
|
17
15
|
|
18
16
|
/// @dev Return the NftId zero (0)
|
19
|
-
function zeroNftId() pure returns(NftId) {
|
17
|
+
function zeroNftId() pure returns (NftId) {
|
18
|
+
return NftId.wrap(0);
|
19
|
+
}
|
20
20
|
|
21
21
|
// pure free functions for operators
|
22
|
-
function eqNftId(NftId a, NftId b) pure returns(bool isSame) {
|
23
|
-
|
22
|
+
function eqNftId(NftId a, NftId b) pure returns (bool isSame) {
|
23
|
+
return NftId.unwrap(a) == NftId.unwrap(b);
|
24
|
+
}
|
25
|
+
|
26
|
+
function neNftId(NftId a, NftId b) pure returns (bool isDifferent) {
|
27
|
+
return NftId.unwrap(a) != NftId.unwrap(b);
|
28
|
+
}
|
24
29
|
|
25
30
|
// library functions that operate on user defined type
|
26
31
|
library NftIdLib {
|
27
32
|
/// @dev Converts the NftId to a uint256.
|
28
|
-
function toInt(NftId nftId) public pure returns(uint96) {
|
33
|
+
function toInt(NftId nftId) public pure returns (uint96) {
|
34
|
+
return uint96(NftId.unwrap(nftId));
|
35
|
+
}
|
36
|
+
|
29
37
|
/// @dev Returns true if the value is non-zero (> 0).
|
30
|
-
function gtz(NftId a) public pure returns(bool) {
|
38
|
+
function gtz(NftId a) public pure returns (bool) {
|
39
|
+
return NftId.unwrap(a) > 0;
|
40
|
+
}
|
41
|
+
|
31
42
|
/// @dev Returns true if the value is zero (== 0).
|
32
|
-
function eqz(NftId a) public pure returns(bool) {
|
43
|
+
function eqz(NftId a) public pure returns (bool) {
|
44
|
+
return NftId.unwrap(a) == 0;
|
45
|
+
}
|
46
|
+
|
33
47
|
/// @dev Returns true if the values are equal (==).
|
34
|
-
function eq(NftId a, NftId b) public pure returns(bool isSame) {
|
48
|
+
function eq(NftId a, NftId b) public pure returns (bool isSame) {
|
49
|
+
return eqNftId(a, b);
|
50
|
+
}
|
35
51
|
}
|
@@ -0,0 +1,107 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
// uint96 allows for chain ids up to 13 digits
|
5
|
+
type ObjectType is uint8;
|
6
|
+
|
7
|
+
// type bindings
|
8
|
+
using {
|
9
|
+
eqObjectType as ==,
|
10
|
+
neObjectType as !=,
|
11
|
+
ObjectTypeLib.toInt
|
12
|
+
} for ObjectType global;
|
13
|
+
|
14
|
+
// general pure free functions
|
15
|
+
|
16
|
+
function PROTOCOL() pure returns (ObjectType) {
|
17
|
+
return toObjectType(10);
|
18
|
+
}
|
19
|
+
|
20
|
+
function CHAIN() pure returns (ObjectType) {
|
21
|
+
return toObjectType(20);
|
22
|
+
}
|
23
|
+
|
24
|
+
function REGISTRY() pure returns (ObjectType) {
|
25
|
+
return toObjectType(30);
|
26
|
+
}
|
27
|
+
|
28
|
+
function TOKEN() pure returns (ObjectType) {
|
29
|
+
return toObjectType(40);
|
30
|
+
}
|
31
|
+
|
32
|
+
function INSTANCE() pure returns (ObjectType) {
|
33
|
+
return toObjectType(50);
|
34
|
+
}
|
35
|
+
|
36
|
+
function PRODUCT() pure returns (ObjectType) {
|
37
|
+
return toObjectType(60);
|
38
|
+
}
|
39
|
+
|
40
|
+
function ORACLE() pure returns (ObjectType) {
|
41
|
+
return toObjectType(70);
|
42
|
+
}
|
43
|
+
|
44
|
+
function POOL() pure returns (ObjectType) {
|
45
|
+
return toObjectType(80);
|
46
|
+
}
|
47
|
+
|
48
|
+
function BUNDLE() pure returns (ObjectType) {
|
49
|
+
return toObjectType(81);
|
50
|
+
}
|
51
|
+
|
52
|
+
function POLICY() pure returns (ObjectType) {
|
53
|
+
return toObjectType(90);
|
54
|
+
}
|
55
|
+
|
56
|
+
function CLAIM() pure returns (ObjectType) {
|
57
|
+
return toObjectType(91);
|
58
|
+
}
|
59
|
+
|
60
|
+
function PAYOUT() pure returns (ObjectType) {
|
61
|
+
return toObjectType(92);
|
62
|
+
}
|
63
|
+
|
64
|
+
/// @dev Converts the uint8 to a ObjectType.
|
65
|
+
function toObjectType(uint256 objectType) pure returns (ObjectType) {
|
66
|
+
return ObjectType.wrap(uint8(objectType));
|
67
|
+
}
|
68
|
+
|
69
|
+
/// @dev Return the ObjectType zero (0)
|
70
|
+
function zeroObjectType() pure returns (ObjectType) {
|
71
|
+
return ObjectType.wrap(0);
|
72
|
+
}
|
73
|
+
|
74
|
+
// pure free functions for operators
|
75
|
+
function eqObjectType(ObjectType a, ObjectType b) pure returns (bool isSame) {
|
76
|
+
return ObjectType.unwrap(a) == ObjectType.unwrap(b);
|
77
|
+
}
|
78
|
+
|
79
|
+
function neObjectType(
|
80
|
+
ObjectType a,
|
81
|
+
ObjectType b
|
82
|
+
) pure returns (bool isDifferent) {
|
83
|
+
return ObjectType.unwrap(a) != ObjectType.unwrap(b);
|
84
|
+
}
|
85
|
+
|
86
|
+
// library functions that operate on user defined type
|
87
|
+
library ObjectTypeLib {
|
88
|
+
/// @dev Converts the NftId to a uint256.
|
89
|
+
function toInt(ObjectType objectType) public pure returns (uint96) {
|
90
|
+
return uint96(ObjectType.unwrap(objectType));
|
91
|
+
}
|
92
|
+
|
93
|
+
/// @dev Returns true if the value is non-zero (> 0).
|
94
|
+
function gtz(ObjectType a) public pure returns (bool) {
|
95
|
+
return ObjectType.unwrap(a) > 0;
|
96
|
+
}
|
97
|
+
|
98
|
+
/// @dev Returns true if the value is zero (== 0).
|
99
|
+
function eqz(ObjectType a) public pure returns (bool) {
|
100
|
+
return ObjectType.unwrap(a) == 0;
|
101
|
+
}
|
102
|
+
|
103
|
+
/// @dev Returns true if the values are equal (==).
|
104
|
+
function eq(ObjectType a, ObjectType b) public pure returns (bool isSame) {
|
105
|
+
return eqObjectType(a, b);
|
106
|
+
}
|
107
|
+
}
|
@@ -0,0 +1,91 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
// uint96 allows for chain ids up to 13 digits
|
5
|
+
type StateId is uint8;
|
6
|
+
|
7
|
+
// type bindings
|
8
|
+
using {eqStateId as ==, neStateId as !=, StateIdLib.toInt} for StateId global;
|
9
|
+
|
10
|
+
// general pure free functions
|
11
|
+
function APPLIED() pure returns (StateId) {
|
12
|
+
return toStateId(10);
|
13
|
+
}
|
14
|
+
|
15
|
+
function REVOKED() pure returns (StateId) {
|
16
|
+
return toStateId(20);
|
17
|
+
}
|
18
|
+
|
19
|
+
function DECLINED() pure returns (StateId) {
|
20
|
+
return toStateId(30);
|
21
|
+
}
|
22
|
+
|
23
|
+
function CONFIRMED() pure returns (StateId) {
|
24
|
+
return toStateId(40);
|
25
|
+
}
|
26
|
+
|
27
|
+
function EXPECTED() pure returns (StateId) {
|
28
|
+
return toStateId(50);
|
29
|
+
}
|
30
|
+
|
31
|
+
function ACTIVE() pure returns (StateId) {
|
32
|
+
return toStateId(100);
|
33
|
+
}
|
34
|
+
|
35
|
+
function PAUSED() pure returns (StateId) {
|
36
|
+
return toStateId(110);
|
37
|
+
}
|
38
|
+
|
39
|
+
function CLOSED() pure returns (StateId) {
|
40
|
+
return toStateId(200);
|
41
|
+
}
|
42
|
+
|
43
|
+
function ARCHIVED() pure returns (StateId) {
|
44
|
+
return toStateId(210);
|
45
|
+
}
|
46
|
+
|
47
|
+
function PAID() pure returns (StateId) {
|
48
|
+
return toStateId(220);
|
49
|
+
}
|
50
|
+
|
51
|
+
/// @dev Converts the uint8 to a StateId.
|
52
|
+
function toStateId(uint256 id) pure returns (StateId) {
|
53
|
+
return StateId.wrap(uint8(id));
|
54
|
+
}
|
55
|
+
|
56
|
+
/// @dev Return the StateId zero (0)
|
57
|
+
function zeroStateId() pure returns (StateId) {
|
58
|
+
return StateId.wrap(0);
|
59
|
+
}
|
60
|
+
|
61
|
+
// pure free functions for operators
|
62
|
+
function eqStateId(StateId a, StateId b) pure returns (bool isSame) {
|
63
|
+
return StateId.unwrap(a) == StateId.unwrap(b);
|
64
|
+
}
|
65
|
+
|
66
|
+
function neStateId(StateId a, StateId b) pure returns (bool isDifferent) {
|
67
|
+
return StateId.unwrap(a) != StateId.unwrap(b);
|
68
|
+
}
|
69
|
+
|
70
|
+
// library functions that operate on user defined type
|
71
|
+
library StateIdLib {
|
72
|
+
/// @dev Converts the NftId to a uint256.
|
73
|
+
function toInt(StateId stateId) public pure returns (uint96) {
|
74
|
+
return uint96(StateId.unwrap(stateId));
|
75
|
+
}
|
76
|
+
|
77
|
+
/// @dev Returns true if the value is non-zero (> 0).
|
78
|
+
function gtz(StateId a) public pure returns (bool) {
|
79
|
+
return StateId.unwrap(a) > 0;
|
80
|
+
}
|
81
|
+
|
82
|
+
/// @dev Returns true if the value is zero (== 0).
|
83
|
+
function eqz(StateId a) public pure returns (bool) {
|
84
|
+
return StateId.unwrap(a) == 0;
|
85
|
+
}
|
86
|
+
|
87
|
+
/// @dev Returns true if the values are equal (==).
|
88
|
+
function eq(StateId a, StateId b) public pure returns (bool isSame) {
|
89
|
+
return eqStateId(a, b);
|
90
|
+
}
|
91
|
+
}
|