@etherisc/gif-next 0.0.2-c83506f-943 → 0.0.2-c96f882-016
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -0
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
- package/artifacts/contracts/components/Distribution.sol/Distribution.json +2 -2
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IDistributionComponent.sol/IDistributionComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPoolComponent.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IProductComponent.sol/IProductComponent.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +1 -1
- package/artifacts/contracts/components/Pool.sol/Pool.json +2 -2
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +2 -2
- package/artifacts/contracts/experiment/cloning/Cloner.sol/Cloner.dbg.json +1 -1
- package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock1.dbg.json +1 -1
- package/artifacts/contracts/experiment/cloning/Cloner.sol/Mock2.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISM.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/ISM.sol/ISMEE.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SM.sol/SM.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +1 -1
- package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.json +13 -0
- package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +1 -1
- package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +15 -2
- package/artifacts/contracts/instance/IAccessManagerSimple.sol/IAccessManagerSimple.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +59 -0
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +138 -81
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +45 -32
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +63 -37
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +80 -28
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +17 -9
- package/artifacts/contracts/instance/base/ComponentServiceBase.sol/ComponentServiceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/IInstanceBase.sol/IInstanceBase.dbg.json +1 -1
- package/artifacts/contracts/instance/base/IKeyValueStore.sol/IKeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/ILifecycle.sol/ILifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/base/KeyValueStore.sol/KeyValueStore.dbg.json +1 -1
- package/artifacts/contracts/instance/base/Lifecycle.sol/Lifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IBundle.sol/IBundle.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IDistribution.sol/IDistribution.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/module/IRisk.sol/IRisk.dbg.json +1 -1
- package/artifacts/contracts/instance/module/ISetup.sol/ISetup.dbg.json +1 -1
- package/artifacts/contracts/instance/module/ITreasury.sol/ITreasury.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ComponentOwnerService.sol/ComponentOwnerService.json +2 -2
- package/artifacts/contracts/instance/service/IComponentOwnerService.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IDistributionService.sol/IDistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IPoolService.sol/IPoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +283 -0
- package/artifacts/contracts/registry/IRegistryService.sol/IRegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/ITransferInterceptor.sol/ITransferInterceptor.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +226 -28
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +8 -8
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +26 -22
- package/artifacts/contracts/shared/ContractDeployerLib.sol/ContractDeployerLib.dbg.json +1 -1
- package/artifacts/contracts/shared/ERC165.sol/ERC165.dbg.json +1 -1
- package/artifacts/contracts/shared/INftOwnable.sol/INftOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/IRegisterable.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/shared/IService.sol/IService.dbg.json +1 -1
- package/artifacts/contracts/shared/IVersionable.sol/IVersionable.dbg.json +1 -1
- package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.dbg.json +1 -1
- package/artifacts/contracts/shared/NftOwnable.sol/NftOwnable.json +2 -2
- package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.dbg.json +1 -1
- package/artifacts/contracts/shared/ProxyManager.sol/ProxyManager.json +2 -2
- package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/shared/Registerable.sol/Registerable.json +2 -2
- package/artifacts/contracts/shared/RegisterableUpgradable.sol/RegisterableUpgradable.dbg.json +1 -1
- package/artifacts/contracts/shared/Service.sol/Service.dbg.json +1 -1
- package/artifacts/contracts/shared/TokenHandler.sol/TokenHandler.dbg.json +1 -1
- package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.dbg.json +1 -1
- package/artifacts/contracts/shared/UpgradableProxyWithAdmin.sol/UpgradableProxyWithAdmin.json +2 -2
- package/artifacts/contracts/shared/Versionable.sol/Versionable.dbg.json +1 -1
- package/artifacts/contracts/test/TestFee.sol/TestFee.dbg.json +1 -1
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.dbg.json +1 -1
- package/artifacts/contracts/test/TestRegisterable.sol/TestRegisterable.json +2 -2
- package/artifacts/contracts/test/TestRoleId.sol/TestRoleId.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.json +2 -2
- package/artifacts/contracts/test/TestToken.sol/TestUsdc.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersion.sol/TestVersion.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersion.sol/TestVersion.json +2 -2
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.dbg.json +1 -1
- package/artifacts/contracts/test/TestVersionable.sol/TestVersionable.json +2 -2
- package/artifacts/contracts/test/Usdc.sol/USDC.dbg.json +1 -1
- package/artifacts/contracts/types/AddressSet.sol/LibAddressSet.dbg.json +1 -1
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/DistributorType.sol/DistributorTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/Fee.sol/FeeLib.dbg.json +1 -1
- package/artifacts/contracts/types/Key32.sol/Key32Lib.dbg.json +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftIdSet.sol/LibNftIdSet.dbg.json +1 -1
- package/artifacts/contracts/types/NumberId.sol/NumberIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/Referral.sol/ReferralLib.dbg.json +1 -1
- package/artifacts/contracts/types/RiskId.sol/RiskIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/RoleId.sol/RoleIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/MathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionLib.json +2 -2
- package/artifacts/contracts/types/Version.sol/VersionPartLib.dbg.json +1 -1
- package/artifacts/contracts/types/Version.sol/VersionPartLib.json +22 -3
- package/contracts/instance/AccessManagedSimple.sol +8 -0
- package/contracts/instance/AccessManagerSimple.sol +10 -0
- package/contracts/instance/IInstanceService.sol +14 -1
- package/contracts/instance/Instance.sol +12 -6
- package/contracts/instance/InstanceReader.sol +10 -0
- package/contracts/instance/InstanceService.sol +54 -18
- package/contracts/registry/IRegistry.sol +35 -2
- package/contracts/registry/Registry.sol +77 -28
- package/contracts/registry/RegistryService.sol +7 -2
- package/contracts/types/Version.sol +4 -1
- package/package.json +1 -1
@@ -26,6 +26,7 @@ import {TimestampLib} from "../types/Timestamp.sol";
|
|
26
26
|
|
27
27
|
|
28
28
|
contract InstanceReader {
|
29
|
+
bool private _initialized;
|
29
30
|
|
30
31
|
IRegistry internal _registry;
|
31
32
|
NftId internal _instanceNftId;
|
@@ -37,6 +38,12 @@ contract InstanceReader {
|
|
37
38
|
NftId instanceNftId
|
38
39
|
)
|
39
40
|
{
|
41
|
+
initialize(registry, instanceNftId);
|
42
|
+
}
|
43
|
+
|
44
|
+
function initialize(address registry, NftId instanceNftId) public {
|
45
|
+
require(!_initialized, "ERROR:CRD-000:ALREADY_INITIALIZED");
|
46
|
+
|
40
47
|
require(
|
41
48
|
address(registry) != address(0),
|
42
49
|
"ERROR:CRD-001:REGISTRY_ZERO");
|
@@ -55,8 +62,11 @@ contract InstanceReader {
|
|
55
62
|
|
56
63
|
_instance = IInstance(instanceInfo.objectAddress);
|
57
64
|
_store = IKeyValueStore(instanceInfo.objectAddress);
|
65
|
+
|
66
|
+
_initialized = true;
|
58
67
|
}
|
59
68
|
|
69
|
+
|
60
70
|
// module specific functions
|
61
71
|
|
62
72
|
function getPolicyInfo(NftId policyNftId)
|
@@ -7,18 +7,22 @@ import {AccessManagerSimple} from "./AccessManagerSimple.sol";
|
|
7
7
|
import {InstanceAccessManager} from "./InstanceAccessManager.sol";
|
8
8
|
import {Instance} from "./Instance.sol";
|
9
9
|
import {IInstanceService} from "./IInstanceService.sol";
|
10
|
-
import {
|
10
|
+
import {InstanceReader} from "./InstanceReader.sol";
|
11
11
|
import {IRegistry} from "../registry/IRegistry.sol";
|
12
|
+
import {Registry} from "../registry/Registry.sol";
|
13
|
+
import {RegistryService} from "../registry/RegistryService.sol";
|
14
|
+
import {Service} from "../../contracts/shared/Service.sol";
|
12
15
|
import {IService} from "../shared/IService.sol";
|
13
16
|
import {ContractDeployerLib} from "../shared/ContractDeployerLib.sol";
|
14
|
-
import {NftId, NftIdLib, zeroNftId} from "
|
17
|
+
import {NftId, NftIdLib, zeroNftId} from "../../contracts/types/NftId.sol";
|
18
|
+
import {VersionLib} from "../types/Version.sol";
|
15
19
|
|
16
20
|
contract InstanceService is Service, IInstanceService {
|
17
21
|
|
18
22
|
address internal _registryAddress;
|
19
23
|
address internal _accessManagerMaster;
|
20
|
-
address internal _instanceAccessManagerMaster;
|
21
24
|
address internal _instanceMaster;
|
25
|
+
address internal _instanceReaderMaster;
|
22
26
|
|
23
27
|
// TODO update to real hash when instance is stable
|
24
28
|
bytes32 public constant INSTANCE_CREATION_CODE_HASH = bytes32(0);
|
@@ -27,31 +31,63 @@ contract InstanceService is Service, IInstanceService {
|
|
27
31
|
function createInstanceClone()
|
28
32
|
external
|
29
33
|
returns (
|
30
|
-
AccessManagerSimple
|
31
|
-
|
32
|
-
|
34
|
+
AccessManagerSimple clonedAccessManager,
|
35
|
+
Instance clonedInstance,
|
36
|
+
NftId instanceNftId,
|
37
|
+
InstanceReader clonedInstanceReader
|
33
38
|
)
|
34
39
|
{
|
35
|
-
|
36
|
-
|
37
|
-
|
40
|
+
Registry registry = Registry(_registryAddress);
|
41
|
+
NftId registryNftId = registry.getNftId(_registryAddress);
|
42
|
+
address registryServiceAddress = registry.getServiceAddress("RegistryService", VersionLib.toVersion(3, 0, 0).toMajorPart());
|
43
|
+
RegistryService registryService = RegistryService(registryServiceAddress);
|
44
|
+
|
45
|
+
clonedAccessManager = AccessManagerSimple(Clones.clone(_accessManagerMaster));
|
46
|
+
clonedAccessManager.initialize(msg.sender);
|
47
|
+
|
48
|
+
clonedInstance = Instance(Clones.clone(_instanceMaster));
|
49
|
+
clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
|
50
|
+
( IRegistry.ObjectInfo memory info, ) = registryService.registerInstance(clonedInstance);
|
51
|
+
instanceNftId = info.nftId;
|
52
|
+
|
53
|
+
clonedInstanceReader = InstanceReader(Clones.clone(address(_instanceReaderMaster)));
|
54
|
+
clonedInstanceReader.initialize(_registryAddress, instanceNftId);
|
55
|
+
|
56
|
+
emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), instanceNftId);
|
38
57
|
}
|
39
58
|
|
40
|
-
function setAccessManagerMaster(address
|
41
|
-
|
59
|
+
function setAccessManagerMaster(address accessManagerMaster) external {
|
60
|
+
require(
|
61
|
+
_accessManagerMaster == address(0),
|
62
|
+
"ERROR:CRD-001:ACCESS_MANAGER_MASTER_ALREADY_SET");
|
63
|
+
_accessManagerMaster = accessManagerMaster;
|
42
64
|
}
|
43
65
|
|
44
|
-
function
|
45
|
-
|
66
|
+
function setInstanceMaster(address instanceMaster) external {
|
67
|
+
require(
|
68
|
+
_instanceMaster == address(0),
|
69
|
+
"ERROR:CRD-002:INSTANCE_MASTER_ALREADY_SET");
|
70
|
+
_instanceMaster = instanceMaster;
|
46
71
|
}
|
47
72
|
|
48
|
-
function
|
49
|
-
|
73
|
+
function setInstanceReaderMaster(address instanceReaderMaster) external {
|
74
|
+
require(
|
75
|
+
_instanceReaderMaster == address(0),
|
76
|
+
"ERROR:CRD-003:INSTANCE_READER_MASTER_ALREADY_SET");
|
77
|
+
_instanceReaderMaster = instanceReaderMaster;
|
50
78
|
}
|
51
79
|
|
52
|
-
function
|
53
|
-
|
54
|
-
|
80
|
+
function getInstanceReaderMaster() external view returns (address) {
|
81
|
+
return _instanceReaderMaster;
|
82
|
+
}
|
83
|
+
|
84
|
+
function getInstanceMaster() external view returns (address) {
|
85
|
+
return _instanceMaster;
|
86
|
+
}
|
87
|
+
|
88
|
+
function getAccessManagerMaster() external view returns (address) {
|
89
|
+
return _accessManagerMaster;
|
90
|
+
}
|
55
91
|
|
56
92
|
// From IService
|
57
93
|
function getName() public pure override(IService, Service) returns(string memory) {
|
@@ -10,10 +10,33 @@ import {VersionPart} from "../types/Version.sol";
|
|
10
10
|
|
11
11
|
interface IRegistry is IERC165 {
|
12
12
|
|
13
|
+
event LogInitialMajorVersionSet(VersionPart majorVersion);
|
14
|
+
event LogMajorVersionSet(VersionPart majorVersionMax);
|
13
15
|
event LogRegistration(ObjectInfo info);
|
14
|
-
|
16
|
+
event LogTokenStateSet(address token, VersionPart majorVersion, bool active);
|
15
17
|
event LogServiceNameRegistration(string serviceName, VersionPart majorVersion);
|
16
18
|
|
19
|
+
// supported versions
|
20
|
+
error MajorVersionMaxIncreaseInvalid(VersionPart newMajorVersionMax, VersionPart existingMaxMajorVersion);
|
21
|
+
|
22
|
+
// token whitelisting
|
23
|
+
error TokenNotRegistered(address token);
|
24
|
+
error NotToken(address token);
|
25
|
+
error TokenMajorVersionInvalid(VersionPart majorVersion);
|
26
|
+
|
27
|
+
// register
|
28
|
+
error NotRegistryService();
|
29
|
+
error ZeroParentAddress();
|
30
|
+
error ContractAlreadyRegistered(address objectAddress);
|
31
|
+
error InvalidServiceVersion(VersionPart majorVersion);
|
32
|
+
error ServiceNameAlreadyRegistered(string name, VersionPart majorVersion);
|
33
|
+
|
34
|
+
// approve
|
35
|
+
error NotOwner(address account);
|
36
|
+
error NotRegisteredContract(NftId registrarNftId);
|
37
|
+
error NotService(NftId registrarNftId);
|
38
|
+
error InvalidTypesCombination(ObjectType objectType, ObjectType parentType);
|
39
|
+
|
17
40
|
|
18
41
|
struct ObjectInfo {
|
19
42
|
NftId nftId;
|
@@ -24,12 +47,20 @@ interface IRegistry is IERC165 {
|
|
24
47
|
address initialOwner;
|
25
48
|
bytes data;
|
26
49
|
}// TODO delete nftId and initialOwner(if not used) from struct
|
50
|
+
// TODO strong disagree, keep nftId there (lets keep get object info return object consistent)
|
51
|
+
|
52
|
+
function setMajorVersion(VersionPart newMajorVersionMax) external;
|
27
53
|
|
28
54
|
function register(ObjectInfo memory info) external returns (NftId nftId);
|
29
|
-
|
55
|
+
|
56
|
+
function setTokenActive(address token, VersionPart majorVersion, bool active) external;
|
57
|
+
|
58
|
+
function getMajorVersion() external view returns (VersionPart);
|
30
59
|
|
31
60
|
function getObjectCount() external view returns (uint256);
|
32
61
|
|
62
|
+
function getNftId() external view returns (NftId nftId);
|
63
|
+
|
33
64
|
function getNftId(address objectAddress) external view returns (NftId nftId);
|
34
65
|
|
35
66
|
function ownerOf(NftId nftId) external view returns (address);
|
@@ -44,6 +75,8 @@ interface IRegistry is IERC165 {
|
|
44
75
|
|
45
76
|
function isRegistered(address contractAddress) external view returns (bool);
|
46
77
|
|
78
|
+
function isTokenActive(address token, VersionPart majorVersion) external view returns (bool);
|
79
|
+
|
47
80
|
function getServiceName(NftId nftId) external view returns (string memory name);
|
48
81
|
|
49
82
|
function getServiceAddress(
|
@@ -7,7 +7,7 @@ import {IService} from "../shared/IService.sol";
|
|
7
7
|
import {ChainNft} from "./ChainNft.sol";
|
8
8
|
import {IRegistry} from "./IRegistry.sol";
|
9
9
|
import {NftId, toNftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
|
10
|
-
import {Version, VersionPart, VersionLib} from "../types/Version.sol";
|
10
|
+
import {Version, VersionPart, VersionLib, VersionPartLib} from "../types/Version.sol";
|
11
11
|
import {ObjectType, PROTOCOL, REGISTRY, TOKEN, SERVICE, INSTANCE, STAKE, PRODUCT, DISTRIBUTION, ORACLE, POOL, POLICY, BUNDLE} from "../types/ObjectType.sol";
|
12
12
|
import {ITransferInterceptor} from "./ITransferInterceptor.sol";
|
13
13
|
|
@@ -28,24 +28,13 @@ contract Registry is
|
|
28
28
|
ERC165,
|
29
29
|
IRegistry
|
30
30
|
{
|
31
|
-
|
32
|
-
error NotRegistryService();
|
33
|
-
error ZeroParentAddress();
|
34
|
-
error ContractAlreadyRegistered(address objectAddress);
|
35
|
-
error InvalidServiceVersion(VersionPart majorVersion);
|
36
|
-
error ServiceNameAlreadyRegistered(string name, VersionPart majorVersion);
|
37
|
-
|
38
|
-
// approve
|
39
|
-
error NotOwner();
|
40
|
-
error NotRegisteredContract(NftId registrarNftId);
|
41
|
-
error NotService(NftId registrarNftId);
|
42
|
-
error InvalidTypesCombination(ObjectType objectType, ObjectType parentType);
|
43
|
-
|
44
|
-
uint256 public constant MAJOR_VERSION_MIN = 3;
|
31
|
+
uint256 public constant GIF_MAJOR_VERSION_AT_DEPLOYMENT = 3;
|
45
32
|
address public constant NFT_LOCK_ADDRESS = address(0x1);
|
46
33
|
uint256 public constant REGISTRY_SERVICE_TOKEN_SEQUENCE_ID = 3;
|
47
34
|
string public constant EMPTY_URI = "";
|
48
35
|
|
36
|
+
VersionPart internal _majorVersion;
|
37
|
+
|
49
38
|
mapping(NftId nftId => ObjectInfo info) internal _info;
|
50
39
|
mapping(address object => NftId nftId) internal _nftIdByAddress;
|
51
40
|
|
@@ -58,6 +47,9 @@ contract Registry is
|
|
58
47
|
mapping(ObjectType objectType => mapping(
|
59
48
|
ObjectType parentType => bool)) internal _isValidObjectCombination;
|
60
49
|
|
50
|
+
mapping(address token => mapping(
|
51
|
+
VersionPart majorVersion => bool isActive)) internal _tokenIsActive;
|
52
|
+
|
61
53
|
mapping(NftId nftId => string name) internal _string;
|
62
54
|
mapping(bytes32 serviceNameHash => mapping(
|
63
55
|
VersionPart majorVersion => address service)) internal _service;
|
@@ -69,7 +61,7 @@ contract Registry is
|
|
69
61
|
|
70
62
|
modifier onlyOwner() {
|
71
63
|
if(msg.sender != getOwner()) {
|
72
|
-
revert NotOwner();
|
64
|
+
revert NotOwner(msg.sender);
|
73
65
|
}
|
74
66
|
_;
|
75
67
|
}
|
@@ -85,7 +77,10 @@ contract Registry is
|
|
85
77
|
constructor(address registryOwner, VersionPart majorVersion)
|
86
78
|
{
|
87
79
|
require(registryOwner > address(0), "Registry: registry owner is 0");
|
88
|
-
|
80
|
+
|
81
|
+
// major version at constructor time
|
82
|
+
_majorVersion = VersionLib.toVersionPart(GIF_MAJOR_VERSION_AT_DEPLOYMENT);
|
83
|
+
emit LogInitialMajorVersionSet(_majorVersion);
|
89
84
|
|
90
85
|
// deploy NFT
|
91
86
|
_chainNft = new ChainNft(address(this));// adds 10kb to deployment size
|
@@ -101,6 +96,24 @@ contract Registry is
|
|
101
96
|
_registerInterface(type(IRegistry).interfaceId);
|
102
97
|
}
|
103
98
|
|
99
|
+
// from IRegistry
|
100
|
+
|
101
|
+
/// @dev latest GIF release version
|
102
|
+
function setMajorVersion(VersionPart newMajorVersion)
|
103
|
+
external
|
104
|
+
onlyOwner
|
105
|
+
{
|
106
|
+
// ensure major version increments is one
|
107
|
+
uint256 oldMax = _majorVersion.toInt();
|
108
|
+
uint256 newMax = newMajorVersion.toInt();
|
109
|
+
if (newMax <= oldMax || newMax - oldMax != 1) {
|
110
|
+
revert MajorVersionMaxIncreaseInvalid(newMajorVersion, _majorVersion);
|
111
|
+
}
|
112
|
+
|
113
|
+
_majorVersion = newMajorVersion;
|
114
|
+
emit LogMajorVersionSet(_majorVersion);
|
115
|
+
}
|
116
|
+
|
104
117
|
/// @dev registry protects only against tampering existing records, registering with invalid types pairs and 0 parent address
|
105
118
|
// TODO service registration means its approval for some type?
|
106
119
|
// TODO registration of precompile addresses
|
@@ -169,12 +182,50 @@ contract Registry is
|
|
169
182
|
emit LogRegistration(info);
|
170
183
|
}
|
171
184
|
|
172
|
-
|
185
|
+
/// @dev token state is informative, registry have no clue about used tokens
|
186
|
+
// component owner is responsible for token selection and operations
|
187
|
+
// service MUST deny registration of component with inactive token
|
188
|
+
function setTokenActive(address token, VersionPart majorVersion, bool active)
|
189
|
+
external
|
190
|
+
onlyOwner
|
191
|
+
{
|
192
|
+
// verify that token is registered
|
193
|
+
ObjectInfo memory info = _info[_nftIdByAddress[token]];
|
194
|
+
if (info.nftId.eqz()) {
|
195
|
+
revert TokenNotRegistered(token);
|
196
|
+
}
|
197
|
+
|
198
|
+
// verify provided address is a registered token
|
199
|
+
if (info.objectType != TOKEN()) {
|
200
|
+
revert NotToken(token);
|
201
|
+
}
|
202
|
+
|
203
|
+
// verify valid major version
|
204
|
+
// ensure major version increments is one
|
205
|
+
uint256 version = majorVersion.toInt();
|
206
|
+
uint256 versionNow = _majorVersion.toInt();
|
207
|
+
if (version < GIF_MAJOR_VERSION_AT_DEPLOYMENT || version > versionNow) {
|
208
|
+
revert TokenMajorVersionInvalid(majorVersion);
|
209
|
+
}
|
210
|
+
|
211
|
+
_tokenIsActive[token][majorVersion] = active;
|
212
|
+
|
213
|
+
emit LogTokenStateSet(token, majorVersion, active);
|
214
|
+
}
|
215
|
+
|
216
|
+
/// @dev latest GIF release version
|
217
|
+
function getMajorVersion() external view returns (VersionPart) {
|
218
|
+
return _majorVersion;
|
219
|
+
}
|
220
|
+
|
173
221
|
function getObjectCount() external view override returns (uint256) {
|
174
|
-
|
175
222
|
return _chainNft.totalSupply();
|
176
223
|
}
|
177
224
|
|
225
|
+
function getNftId() external view returns (NftId nftId) {
|
226
|
+
return _registryNftId;
|
227
|
+
}
|
228
|
+
|
178
229
|
function getNftId(address object) external view override returns (NftId id) {
|
179
230
|
return _nftIdByAddress[object];
|
180
231
|
}
|
@@ -205,6 +256,10 @@ contract Registry is
|
|
205
256
|
return _nftIdByAddress[object].gtz();
|
206
257
|
}
|
207
258
|
|
259
|
+
function isTokenActive(address token, VersionPart majorVersion) external view returns (bool) {
|
260
|
+
return _tokenIsActive[token][majorVersion];
|
261
|
+
}
|
262
|
+
|
208
263
|
function getServiceName(NftId nftId) external view returns (string memory) {
|
209
264
|
return _string[nftId];
|
210
265
|
}
|
@@ -238,14 +293,8 @@ contract Registry is
|
|
238
293
|
) = abi.decode(info.data, (string, VersionPart));
|
239
294
|
bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
|
240
295
|
|
241
|
-
//
|
242
|
-
|
243
|
-
// TODO do not use names -> each object type is registered by corresponding service -> conflicting with approve()
|
244
|
-
if(
|
245
|
-
majorVersion.toInt() < MAJOR_VERSION_MIN ||
|
246
|
-
(majorVersion.toInt() > MAJOR_VERSION_MIN &&
|
247
|
-
_service[serviceNameHash][VersionLib.toVersionPart(majorVersion.toInt() - 1)] == address(0) )
|
248
|
-
) {
|
296
|
+
// ensures consistency of service.getVersion() and majorVersion here
|
297
|
+
if(majorVersion != _majorVersion) {
|
249
298
|
revert InvalidServiceVersion(majorVersion);
|
250
299
|
}
|
251
300
|
|
@@ -386,7 +435,7 @@ contract Registry is
|
|
386
435
|
|
387
436
|
string memory serviceName = "RegistryService";
|
388
437
|
bytes32 serviceNameHash = keccak256(abi.encode(serviceName));
|
389
|
-
_service[serviceNameHash][VersionLib.toVersionPart(
|
438
|
+
_service[serviceNameHash][VersionLib.toVersionPart(GIF_MAJOR_VERSION_AT_DEPLOYMENT)] = msg.sender;
|
390
439
|
_string[serviceNftId] = serviceName;
|
391
440
|
_serviceNftId = serviceNftId;
|
392
441
|
}
|
@@ -366,8 +366,13 @@ contract RegistryService is
|
|
366
366
|
|
367
367
|
address owner = info.initialOwner;
|
368
368
|
|
369
|
-
|
370
|
-
|
369
|
+
// solhint-disable-next-line
|
370
|
+
if(expectedType == INSTANCE()) {
|
371
|
+
// any address may create a new instance via instance service
|
372
|
+
} else {
|
373
|
+
if(owner != expectedOwner) { // registerable owner protection
|
374
|
+
revert NotRegisterableOwner(expectedOwner);
|
375
|
+
}
|
371
376
|
}
|
372
377
|
|
373
378
|
if(owner == address(registerable)) {
|
@@ -6,15 +6,18 @@ type VersionPart is uint8;
|
|
6
6
|
using {
|
7
7
|
versionPartGt as >,
|
8
8
|
versionPartEq as ==,
|
9
|
+
versionPartNe as !=,
|
9
10
|
VersionPartLib.toInt
|
10
11
|
}
|
11
12
|
for VersionPart global;
|
12
13
|
|
13
14
|
function versionPartGt(VersionPart a, VersionPart b) pure returns(bool isGreaterThan) { return VersionPart.unwrap(a) > VersionPart.unwrap(b); }
|
14
15
|
function versionPartEq(VersionPart a, VersionPart b) pure returns(bool isSame) { return VersionPart.unwrap(a) == VersionPart.unwrap(b); }
|
16
|
+
function versionPartNe(VersionPart a, VersionPart b) pure returns(bool isSame) { return VersionPart.unwrap(a) != VersionPart.unwrap(b); }
|
15
17
|
|
16
18
|
library VersionPartLib {
|
17
|
-
function toInt(VersionPart
|
19
|
+
function toInt(VersionPart a) external pure returns(uint) { return VersionPart.unwrap(a); }
|
20
|
+
function toVersionPart(uint256 a) external pure returns(VersionPart) { return VersionPart.wrap(uint8(a)); }
|
18
21
|
}
|
19
22
|
|
20
23
|
type Version is uint24; // contains major,minor,patch version parts
|
package/package.json
CHANGED