@etherisc/gif-next 0.0.2-ed4dd55 → 0.0.2-f824182-503
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 +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,68 +1,67 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
+
import {NftId} from "../types/NftId.sol";
|
5
|
+
import {ObjectType} from "../types/ObjectType.sol";
|
6
|
+
|
4
7
|
interface IOwnable {
|
5
|
-
function getOwner() external view returns(address owner);
|
8
|
+
function getOwner() external view returns (address owner);
|
6
9
|
}
|
7
10
|
|
8
11
|
interface IRegistryLinked {
|
9
|
-
|
10
12
|
event LogDebug(uint256 idx, address module, string comment);
|
11
13
|
|
12
|
-
function getRegistry() external view returns(IRegistry registry);
|
14
|
+
function getRegistry() external view returns (IRegistry registry);
|
13
15
|
}
|
14
16
|
|
15
|
-
interface IRegisterable is
|
16
|
-
|
17
|
-
IRegistryLinked
|
18
|
-
{
|
19
|
-
|
20
|
-
function register() external returns(uint256 nftId);
|
21
|
-
|
22
|
-
function getNftId() external view returns(uint256 nftId);
|
23
|
-
function getParentNftId() external view returns(uint256 parentNftId);
|
24
|
-
function getType() external view returns(uint256 objectType);
|
25
|
-
function getData() external view returns(bytes memory data);
|
26
|
-
function isRegisterable() external pure returns(bool);
|
27
|
-
function getInitialOwner() external view returns(address initialOwner);
|
28
|
-
|
29
|
-
function isRegistered() external view returns(bool);
|
30
|
-
}
|
17
|
+
interface IRegisterable is IOwnable, IRegistryLinked {
|
18
|
+
function register() external returns (NftId nftId);
|
31
19
|
|
20
|
+
function getNftId() external view returns (NftId nftId);
|
32
21
|
|
33
|
-
|
22
|
+
function getParentNftId() external view returns (NftId parentNftId);
|
23
|
+
|
24
|
+
function getType() external view returns (ObjectType objectType);
|
25
|
+
|
26
|
+
function getData() external view returns (bytes memory data);
|
27
|
+
|
28
|
+
function isRegisterable() external pure returns (bool);
|
34
29
|
|
30
|
+
function getInitialOwner() external view returns (address initialOwner);
|
31
|
+
|
32
|
+
function isRegistered() external view returns (bool);
|
33
|
+
}
|
34
|
+
|
35
|
+
interface IRegistry {
|
35
36
|
struct RegistryInfo {
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
NftId nftId;
|
38
|
+
NftId parentNftId;
|
39
|
+
ObjectType objectType;
|
39
40
|
address objectAddress;
|
40
41
|
address initialOwner;
|
41
42
|
}
|
42
43
|
|
43
|
-
function
|
44
|
-
function INSTANCE() external pure returns(uint256);
|
45
|
-
function PRODUCT() external pure returns(uint256);
|
46
|
-
function ORACLE() external pure returns(uint256);
|
47
|
-
function POOL() external pure returns(uint256);
|
48
|
-
function POLICY() external pure returns(uint256);
|
49
|
-
function BUNDLE() external pure returns(uint256);
|
44
|
+
function register(address objectAddress) external returns (NftId nftId);
|
50
45
|
|
51
|
-
function register(address objectAddress) external returns(uint256 nftId);
|
52
46
|
function registerObjectForInstance(
|
53
|
-
|
54
|
-
|
47
|
+
NftId parentNftid,
|
48
|
+
ObjectType objectType,
|
55
49
|
address initialOwner
|
56
|
-
)
|
57
|
-
|
50
|
+
) external returns (NftId nftId);
|
51
|
+
|
52
|
+
function getObjectCount() external view returns (uint256);
|
53
|
+
|
54
|
+
function getNftId(
|
55
|
+
address objectAddress
|
56
|
+
) external view returns (NftId nftId);
|
58
57
|
|
59
|
-
function
|
58
|
+
function getInfo(
|
59
|
+
NftId nftId
|
60
|
+
) external view returns (RegistryInfo memory info);
|
60
61
|
|
61
|
-
function
|
62
|
-
function getInfo(uint256 nftId) external view returns(RegistryInfo memory info);
|
63
|
-
function getOwner(uint256 nftId) external view returns(address ownerAddress);
|
62
|
+
function getOwner(NftId nftId) external view returns (address ownerAddress);
|
64
63
|
|
65
|
-
function isRegistered(address objectAddress) external view returns(bool);
|
64
|
+
function isRegistered(address objectAddress) external view returns (bool);
|
66
65
|
|
67
|
-
function getNftAddress() external view returns(address nft);
|
66
|
+
function getNftAddress() external view returns (address nft);
|
68
67
|
}
|
@@ -3,102 +3,105 @@ 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, NftIdLib} from "../types/NftId.sol";
|
7
|
+
import {ObjectType, INSTANCE, POLICY, BUNDLE} from "../types/ObjectType.sol";
|
6
8
|
|
7
9
|
contract RegistryLinked is IRegistryLinked {
|
8
|
-
|
9
10
|
IRegistry internal _registry;
|
10
|
-
|
11
|
+
|
11
12
|
constructor(address registry) {
|
12
13
|
_registry = IRegistry(registry);
|
13
14
|
}
|
14
15
|
|
15
|
-
function getRegistry() external view override returns(IRegistry registry) {
|
16
|
+
function getRegistry() external view override returns (IRegistry registry) {
|
16
17
|
return _registry;
|
17
18
|
}
|
18
|
-
|
19
19
|
}
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
RegistryLinked,
|
24
|
-
IRegisterable
|
25
|
-
{
|
21
|
+
abstract contract Registerable is RegistryLinked, IRegisterable {
|
22
|
+
using NftIdLib for NftId;
|
26
23
|
|
27
24
|
address private _initialOwner;
|
28
|
-
|
29
|
-
constructor(address registry)
|
30
|
-
RegistryLinked(registry)
|
31
|
-
{
|
25
|
+
|
26
|
+
constructor(address registry) RegistryLinked(registry) {
|
32
27
|
_initialOwner = msg.sender;
|
33
28
|
}
|
34
29
|
|
35
30
|
// getType, getData and register need to be implemented by concrete contract
|
36
31
|
|
37
|
-
function isRegisterable() external pure override returns(bool) {
|
32
|
+
function isRegisterable() external pure override returns (bool) {
|
38
33
|
return true;
|
39
34
|
}
|
40
35
|
|
41
|
-
function getInitialOwner() public view override returns(address deployer) {
|
36
|
+
function getInitialOwner() public view override returns (address deployer) {
|
42
37
|
return _initialOwner;
|
43
38
|
}
|
44
39
|
|
45
|
-
function isRegistered() public view override returns(bool) {
|
46
|
-
|
40
|
+
function isRegistered() public view override returns (bool) {
|
41
|
+
NftId nftId = _registry.getNftId(address(this));
|
42
|
+
return nftId.gtz();
|
47
43
|
}
|
48
44
|
|
49
|
-
function getNftId() public view override returns(
|
45
|
+
function getNftId() public view override returns (NftId nftId) {
|
50
46
|
return _registry.getNftId(address(this));
|
51
47
|
}
|
52
48
|
|
53
|
-
function getOwner() public view override returns(address owner) {
|
54
|
-
|
49
|
+
function getOwner() public view override returns (address owner) {
|
50
|
+
NftId id = _registry.getNftId(address(this));
|
55
51
|
owner = _registry.getOwner(id);
|
56
52
|
return owner != address(0) ? owner : _initialOwner;
|
57
53
|
}
|
58
|
-
|
59
54
|
}
|
60
55
|
|
61
56
|
contract Registry is IRegistry {
|
57
|
+
using NftIdLib for NftId;
|
62
58
|
|
63
59
|
string public constant EMPTY_URI = "";
|
64
60
|
|
65
|
-
mapping(
|
66
|
-
mapping(
|
67
|
-
mapping(address object =>
|
61
|
+
mapping(NftId nftId => RegistryInfo info) private _info;
|
62
|
+
mapping(NftId nftId => address owner) private _owner;
|
63
|
+
mapping(address object => NftId nftId) private _nftIdByAddress;
|
68
64
|
|
69
65
|
IChainNft private _chainNft;
|
70
66
|
|
71
67
|
function initialize(address chainNft) external {
|
72
|
-
require(
|
68
|
+
require(
|
69
|
+
address(_chainNft) == address(0),
|
70
|
+
"ERROR:REG-001:ALREADY_INITIALIZED"
|
71
|
+
);
|
73
72
|
_chainNft = IChainNft(chainNft);
|
74
73
|
}
|
75
74
|
|
76
|
-
function
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
function register(address objectAddress) external override returns(uint256 nftId) {
|
85
|
-
require(_idByAddress[objectAddress] == 0, "ERROR:REG-001: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
|
+
);
|
86
82
|
|
87
83
|
IRegisterable registerable = IRegisterable(objectAddress);
|
88
|
-
require(
|
84
|
+
require(
|
85
|
+
registerable.isRegisterable(),
|
86
|
+
"ERROR:REG-003:NOT_REGISTERABLE"
|
87
|
+
);
|
89
88
|
|
90
89
|
// check parent exists (for objects not instances)
|
91
|
-
if(registerable.getType() != INSTANCE()) {
|
92
|
-
RegistryInfo memory parentInfo = _info[
|
93
|
-
|
90
|
+
if (registerable.getType() != INSTANCE()) {
|
91
|
+
RegistryInfo memory parentInfo = _info[
|
92
|
+
registerable.getParentNftId()
|
93
|
+
];
|
94
|
+
require(parentInfo.nftId.gtz(), "ERROR:REG-004:PARENT_NOT_FOUND");
|
94
95
|
// check validity of parent relation, valid relations are
|
95
96
|
// policy -> product, bundle -> pool, product -> instance, pool -> instance
|
96
97
|
}
|
97
98
|
|
98
|
-
|
99
|
-
registerable.getInitialOwner(),
|
100
|
-
EMPTY_URI
|
101
|
-
|
99
|
+
uint256 mintedTokenId = _chainNft.mint(
|
100
|
+
registerable.getInitialOwner(),
|
101
|
+
EMPTY_URI
|
102
|
+
);
|
103
|
+
nftId = toNftId(mintedTokenId);
|
104
|
+
|
102
105
|
RegistryInfo memory info = RegistryInfo(
|
103
106
|
nftId,
|
104
107
|
registerable.getParentNftId(),
|
@@ -108,30 +111,31 @@ contract Registry is IRegistry {
|
|
108
111
|
);
|
109
112
|
|
110
113
|
_info[nftId] = info;
|
111
|
-
|
114
|
+
_nftIdByAddress[objectAddress] = nftId;
|
112
115
|
|
113
116
|
// add logging
|
114
117
|
}
|
115
118
|
|
116
|
-
|
117
119
|
function registerObjectForInstance(
|
118
|
-
|
119
|
-
|
120
|
+
NftId parentNftId,
|
121
|
+
ObjectType objectType,
|
120
122
|
address initialOwner
|
121
123
|
)
|
122
|
-
external
|
124
|
+
external
|
123
125
|
override
|
124
|
-
|
125
|
-
|
126
|
+
returns (
|
127
|
+
// TODO add onlyRegisteredInstance
|
128
|
+
NftId nftId
|
129
|
+
)
|
126
130
|
{
|
127
131
|
// TODO add more validation
|
128
132
|
require(
|
129
133
|
objectType == POLICY() || objectType == BUNDLE(),
|
130
|
-
"ERROR:REG-005:TYPE_INVALID"
|
134
|
+
"ERROR:REG-005:TYPE_INVALID"
|
135
|
+
);
|
131
136
|
|
132
|
-
|
133
|
-
|
134
|
-
EMPTY_URI);
|
137
|
+
uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
|
138
|
+
nftId = toNftId(mintedTokenId);
|
135
139
|
|
136
140
|
RegistryInfo memory info = RegistryInfo(
|
137
141
|
nftId,
|
@@ -146,31 +150,33 @@ contract Registry is IRegistry {
|
|
146
150
|
// add logging
|
147
151
|
}
|
148
152
|
|
149
|
-
|
150
|
-
function getObjectCount() external view override returns(uint256) {
|
153
|
+
function getObjectCount() external view override returns (uint256) {
|
151
154
|
return _chainNft.totalSupply();
|
152
155
|
}
|
153
156
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
+
function getNftId(
|
158
|
+
address object
|
159
|
+
) external view override returns (NftId id) {
|
160
|
+
return _nftIdByAddress[object];
|
157
161
|
}
|
158
162
|
|
159
|
-
|
160
|
-
|
161
|
-
|
163
|
+
function isRegistered(
|
164
|
+
address object
|
165
|
+
) external view override returns (bool) {
|
166
|
+
return _nftIdByAddress[object].gtz();
|
162
167
|
}
|
163
168
|
|
164
|
-
|
165
|
-
|
169
|
+
function getInfo(
|
170
|
+
NftId nftId
|
171
|
+
) external view override returns (RegistryInfo memory info) {
|
166
172
|
return _info[nftId];
|
167
173
|
}
|
168
174
|
|
169
|
-
function getOwner(
|
170
|
-
return _chainNft.ownerOf(nftId);
|
175
|
+
function getOwner(NftId nftId) external view override returns (address) {
|
176
|
+
return _chainNft.ownerOf(nftId.toInt());
|
171
177
|
}
|
172
178
|
|
173
|
-
function getNftAddress() external view override returns(address nft) {
|
179
|
+
function getNftAddress() external view override returns (address nft) {
|
174
180
|
return address(_chainNft);
|
175
181
|
}
|
176
182
|
}
|
@@ -0,0 +1,118 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
type Blocknumber is uint32;
|
5
|
+
|
6
|
+
using {
|
7
|
+
gtBlocknumber as >,
|
8
|
+
gteBlocknumber as >=,
|
9
|
+
ltBlocknumber as <,
|
10
|
+
lteBlocknumber as <=,
|
11
|
+
eqBlocknumber as ==,
|
12
|
+
neBlocknumber as !=,
|
13
|
+
BlocknumberLib.toInt
|
14
|
+
} for Blocknumber global;
|
15
|
+
|
16
|
+
/// @dev return true if Blocknumber a is greater than Blocknumber b
|
17
|
+
function gtBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
18
|
+
return Blocknumber.unwrap(a) > Blocknumber.unwrap(b);
|
19
|
+
}
|
20
|
+
|
21
|
+
/// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
|
22
|
+
function gteBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
23
|
+
return Blocknumber.unwrap(a) >= Blocknumber.unwrap(b);
|
24
|
+
}
|
25
|
+
|
26
|
+
/// @dev return true if Blocknumber a is less than Blocknumber b
|
27
|
+
function ltBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
28
|
+
return Blocknumber.unwrap(a) < Blocknumber.unwrap(b);
|
29
|
+
}
|
30
|
+
|
31
|
+
/// @dev return true if Blocknumber a is less than or equal to Blocknumber b
|
32
|
+
function lteBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
33
|
+
return Blocknumber.unwrap(a) <= Blocknumber.unwrap(b);
|
34
|
+
}
|
35
|
+
|
36
|
+
/// @dev return true if Blocknumber a is equal to Blocknumber b
|
37
|
+
function eqBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
38
|
+
return Blocknumber.unwrap(a) == Blocknumber.unwrap(b);
|
39
|
+
}
|
40
|
+
|
41
|
+
/// @dev return true if Blocknumber a is not equal to Blocknumber b
|
42
|
+
function neBlocknumber(Blocknumber a, Blocknumber b) pure returns (bool) {
|
43
|
+
return Blocknumber.unwrap(a) != Blocknumber.unwrap(b);
|
44
|
+
}
|
45
|
+
|
46
|
+
/// @dev Converts the uint256 to a Blocknumber.
|
47
|
+
function toBlocknumber(uint256 blocknum) pure returns (Blocknumber) {
|
48
|
+
return Blocknumber.wrap(uint32(blocknum));
|
49
|
+
}
|
50
|
+
|
51
|
+
function blockBlocknumber() view returns (Blocknumber) {
|
52
|
+
return toBlocknumber(block.number);
|
53
|
+
}
|
54
|
+
|
55
|
+
/// @dev Return the Blocknumber zero (0)
|
56
|
+
function zeroBlocknumber() pure returns (Blocknumber) {
|
57
|
+
return toBlocknumber(0);
|
58
|
+
}
|
59
|
+
|
60
|
+
/// @dev Return the current block number
|
61
|
+
function blockNumber() view returns (Blocknumber) {
|
62
|
+
return toBlocknumber(block.number);
|
63
|
+
}
|
64
|
+
|
65
|
+
library BlocknumberLib {
|
66
|
+
/// @dev return true if Blocknumber a is greater than Blocknumber b
|
67
|
+
function gt(
|
68
|
+
Blocknumber a,
|
69
|
+
Blocknumber b
|
70
|
+
) public pure returns (bool isAfter) {
|
71
|
+
return gtBlocknumber(a, b);
|
72
|
+
}
|
73
|
+
|
74
|
+
/// @dev return true if Blocknumber a is greater than or equal to Blocknumber b
|
75
|
+
function gte(
|
76
|
+
Blocknumber a,
|
77
|
+
Blocknumber b
|
78
|
+
) public pure returns (bool isAfterOrSame) {
|
79
|
+
return gteBlocknumber(a, b);
|
80
|
+
}
|
81
|
+
|
82
|
+
/// @dev return true if Blocknumber a is less than Blocknumber b
|
83
|
+
function lt(
|
84
|
+
Blocknumber a,
|
85
|
+
Blocknumber b
|
86
|
+
) public pure returns (bool isBefore) {
|
87
|
+
return ltBlocknumber(a, b);
|
88
|
+
}
|
89
|
+
|
90
|
+
/// @dev return true if Blocknumber a is less than or equal to Blocknumber b
|
91
|
+
function lte(
|
92
|
+
Blocknumber a,
|
93
|
+
Blocknumber b
|
94
|
+
) public pure returns (bool isBeforeOrSame) {
|
95
|
+
return lteBlocknumber(a, b);
|
96
|
+
}
|
97
|
+
|
98
|
+
/// @dev return true if Blocknumber a is equal to Blocknumber b
|
99
|
+
function eq(
|
100
|
+
Blocknumber a,
|
101
|
+
Blocknumber b
|
102
|
+
) public pure returns (bool isSame) {
|
103
|
+
return eqBlocknumber(a, b);
|
104
|
+
}
|
105
|
+
|
106
|
+
/// @dev return true if Blocknumber a is not equal to Blocknumber b
|
107
|
+
function ne(
|
108
|
+
Blocknumber a,
|
109
|
+
Blocknumber b
|
110
|
+
) public pure returns (bool isDifferent) {
|
111
|
+
return neBlocknumber(a, b);
|
112
|
+
}
|
113
|
+
|
114
|
+
/// @dev converts the Blocknumber to a uint256
|
115
|
+
function toInt(Blocknumber blocknumber) public pure returns (uint256) {
|
116
|
+
return uint256(uint32(Blocknumber.unwrap(blocknumber)));
|
117
|
+
}
|
118
|
+
}
|
@@ -1,24 +1,38 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.19;
|
3
3
|
|
4
|
-
|
4
|
+
/// @dev bytes5 (uint40) allows for chain ids up to 13 digits
|
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.
|
12
|
+
function toChainId(uint256 chainId) pure returns (ChainId) {
|
13
|
+
return ChainId.wrap(bytes5(uint40(chainId)));
|
14
|
+
}
|
15
|
+
|
16
|
+
/// @dev Return the ChainId for the chain the contract is deployed to
|
17
|
+
function thisChainId() view returns (ChainId) {
|
18
|
+
return toChainId(block.chainid);
|
19
|
+
}
|
16
20
|
|
17
21
|
// pure free functions for operators
|
18
|
-
|
19
|
-
function
|
22
|
+
/// @dev Returns true if the values are equal (==).
|
23
|
+
function eqChainId(ChainId a, ChainId b) pure returns (bool isSame) {
|
24
|
+
return ChainId.unwrap(a) == ChainId.unwrap(b);
|
25
|
+
}
|
26
|
+
|
27
|
+
/// @dev Returns true if the values are not equal (!=).
|
28
|
+
function neChainId(ChainId a, ChainId b) pure returns (bool isDifferent) {
|
29
|
+
return ChainId.unwrap(a) != ChainId.unwrap(b);
|
30
|
+
}
|
20
31
|
|
21
32
|
// library functions that operate on user defined type
|
22
33
|
library ChainIdLib {
|
23
|
-
|
34
|
+
/// @dev Converts the ChainId to a uint256.
|
35
|
+
function toInt(ChainId chainId) internal pure returns (uint256) {
|
36
|
+
return uint256(uint40(ChainId.unwrap(chainId)));
|
37
|
+
}
|
24
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,21 +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
|
-
|
16
|
-
function
|
11
|
+
/// @dev Converts the uint256 to a NftId.
|
12
|
+
function toNftId(uint256 id) pure returns (NftId) {
|
13
|
+
return NftId.wrap(uint96(id));
|
14
|
+
}
|
15
|
+
|
16
|
+
/// @dev Return the NftId zero (0)
|
17
|
+
function zeroNftId() pure returns (NftId) {
|
18
|
+
return NftId.wrap(0);
|
19
|
+
}
|
17
20
|
|
18
21
|
// pure free functions for operators
|
19
|
-
function eqNftId(NftId a, NftId b) pure returns(bool isSame) {
|
20
|
-
|
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
|
+
}
|
21
29
|
|
22
30
|
// library functions that operate on user defined type
|
23
31
|
library NftIdLib {
|
24
|
-
|
32
|
+
/// @dev Converts the NftId to a uint256.
|
33
|
+
function toInt(NftId nftId) public pure returns (uint96) {
|
34
|
+
return uint96(NftId.unwrap(nftId));
|
35
|
+
}
|
36
|
+
|
37
|
+
/// @dev Returns true if the value is non-zero (> 0).
|
38
|
+
function gtz(NftId a) public pure returns (bool) {
|
39
|
+
return NftId.unwrap(a) > 0;
|
40
|
+
}
|
41
|
+
|
42
|
+
/// @dev Returns true if the value is zero (== 0).
|
43
|
+
function eqz(NftId a) public pure returns (bool) {
|
44
|
+
return NftId.unwrap(a) == 0;
|
45
|
+
}
|
46
|
+
|
47
|
+
/// @dev Returns true if the values are equal (==).
|
48
|
+
function eq(NftId a, NftId b) public pure returns (bool isSame) {
|
49
|
+
return eqNftId(a, b);
|
50
|
+
}
|
25
51
|
}
|