@etherisc/gif-next 0.0.2-d10d6b3-916 → 0.0.2-d224a95-375
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 +20 -1
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/BaseComponent.sol/BaseComponent.json +126 -0
- package/artifacts/contracts/components/Distribution.sol/Distribution.dbg.json +1 -1
- package/artifacts/contracts/components/Distribution.sol/Distribution.json +136 -10
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IBaseComponent.sol/IBaseComponent.json +88 -0
- 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 +134 -8
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +134 -8
- 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/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.dbg.json +4 -0
- package/artifacts/contracts/instance/AccessManagerUpgradeableInitializeable.sol/AccessManagerUpgradeableInitializeable.json +1206 -0
- package/artifacts/contracts/instance/BundleManager.sol/BundleManager.dbg.json +1 -1
- package/artifacts/contracts/instance/BundleManager.sol/BundleManager.json +45 -32
- package/artifacts/contracts/instance/Cloneable.sol/Cloneable.dbg.json +1 -1
- 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/IInstanceBase.sol/IInstanceBase.dbg.json +4 -0
- package/artifacts/contracts/instance/IInstanceBase.sol/IInstanceBase.json +448 -0
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstanceService.sol/IInstanceService.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +74 -139
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceAccessManager.sol/InstanceAccessManager.json +55 -32
- package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.dbg.json +4 -0
- package/artifacts/contracts/instance/InstanceBase.sol/InstanceBase.json +763 -0
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceReader.sol/InstanceReader.json +2 -2
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceService.sol/InstanceService.json +74 -61
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/InstanceServiceManager.sol/InstanceServiceManager.json +31 -31
- package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.dbg.json +1 -1
- package/artifacts/contracts/instance/ObjectManager.sol/ObjectManager.json +15 -2
- 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/DistributionService.sol/DistributionService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionService.sol/DistributionService.json +2 -2
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/DistributionServiceManager.sol/DistributionServiceManager.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/instance/service/PoolService.sol/PoolService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolService.sol/PoolService.json +2 -2
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/PoolServiceManager.sol/PoolServiceManager.json +2 -2
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductService.sol/ProductService.json +2 -2
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.dbg.json +1 -1
- package/artifacts/contracts/instance/service/ProductServiceManager.sol/ProductServiceManager.json +2 -2
- 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/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/RegistryService.sol/RegistryService.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryService.sol/RegistryService.json +2 -2
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.dbg.json +1 -1
- package/artifacts/contracts/registry/RegistryServiceManager.sol/RegistryServiceManager.json +2 -2
- package/artifacts/contracts/registry/TokenRegistry.sol/TokenRegistry.dbg.json +1 -1
- 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/ProxyManager.sol/ProxyManager.dbg.json +1 -1
- package/artifacts/contracts/shared/Registerable.sol/Registerable.dbg.json +1 -1
- 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/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/TestRoleId.sol/TestRoleId.dbg.json +1 -1
- package/artifacts/contracts/test/TestService.sol/TestService.dbg.json +1 -1
- 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/TestVersionable.sol/TestVersionable.dbg.json +1 -1
- 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/VersionPartLib.dbg.json +1 -1
- package/contracts/components/BaseComponent.sol +49 -8
- package/contracts/components/IBaseComponent.sol +6 -0
- package/contracts/instance/AccessManagerUpgradeableInitializeable.sol +23 -0
- package/contracts/instance/IInstanceBase.sol +26 -0
- package/contracts/instance/IInstanceService.sol +2 -2
- package/contracts/instance/Instance.sol +15 -14
- package/contracts/instance/InstanceAccessManager.sol +6 -6
- package/contracts/instance/InstanceBase.sol +41 -0
- package/contracts/instance/InstanceService.sol +17 -10
- package/contracts/instance/ObjectManager.sol +7 -1
- package/package.json +1 -1
- package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.dbg.json +0 -4
- package/artifacts/contracts/instance/AccessManagedSimple.sol/AccessManagedSimple.json +0 -101
- package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.dbg.json +0 -4
- package/artifacts/contracts/instance/AccessManagerSimple.sol/AccessManagerSimple.json +0 -1132
- package/contracts/instance/AccessManagedSimple.sol +0 -115
- package/contracts/instance/AccessManagerSimple.sol +0 -692
@@ -1,18 +1,15 @@
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
2
2
|
pragma solidity ^0.8.20;
|
3
3
|
|
4
|
+
import {IBaseComponent} from "./IBaseComponent.sol";
|
5
|
+
import {IComponentOwnerService} from "../instance/service/IComponentOwnerService.sol";
|
4
6
|
import {IERC20Metadata} from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
|
5
|
-
|
6
|
-
import {Registerable} from "../shared/Registerable.sol";
|
7
|
-
|
8
|
-
import {IRegistry} from "../registry/IRegistry.sol";
|
9
|
-
import {IInstance} from "../instance/IInstance.sol";
|
10
|
-
|
11
7
|
import {IInstance} from "../instance/IInstance.sol";
|
12
|
-
import {
|
13
|
-
import {IBaseComponent} from "./IBaseComponent.sol";
|
8
|
+
import {IRegistry} from "../registry/IRegistry.sol";
|
14
9
|
import {NftId, zeroNftId, NftIdLib} from "../types/NftId.sol";
|
15
10
|
import {ObjectType} from "../types/ObjectType.sol";
|
11
|
+
import {Registerable} from "../shared/Registerable.sol";
|
12
|
+
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
16
13
|
|
17
14
|
abstract contract BaseComponent is
|
18
15
|
Registerable,
|
@@ -55,10 +52,12 @@ abstract contract BaseComponent is
|
|
55
52
|
}
|
56
53
|
|
57
54
|
// from component contract
|
55
|
+
// TODO consider to remove/replace with access manager contract locking
|
58
56
|
function lock() external onlyOwner override {
|
59
57
|
_componentOwnerService.lock(this);
|
60
58
|
}
|
61
59
|
|
60
|
+
// TODO consider to remove/replace with access manager contract locking
|
62
61
|
function unlock() external onlyOwner override {
|
63
62
|
_componentOwnerService.unlock(this);
|
64
63
|
}
|
@@ -72,6 +71,48 @@ abstract contract BaseComponent is
|
|
72
71
|
return _wallet;
|
73
72
|
}
|
74
73
|
|
74
|
+
/// @dev Sets the wallet address for the component.
|
75
|
+
/// if the current wallet has tokens, these will be transferred.
|
76
|
+
/// if the new wallet address is externally owned, an approval from the
|
77
|
+
/// owner of the external wallet for the component to move all tokens must exist.
|
78
|
+
function setWallet(address newWallet) external override onlyOwner {
|
79
|
+
address currentWallet = _wallet;
|
80
|
+
uint256 currentBalance = _token.balanceOf(currentWallet);
|
81
|
+
|
82
|
+
// checks
|
83
|
+
if (newWallet == currentWallet) {
|
84
|
+
revert ErrorBaseComponentWalletAddressIsSameAsCurrent(newWallet);
|
85
|
+
}
|
86
|
+
|
87
|
+
if (currentBalance > 0) {
|
88
|
+
if (currentWallet == address(this)) {
|
89
|
+
// move tokens from component smart contract to external wallet
|
90
|
+
} else {
|
91
|
+
// move tokens from external wallet to component smart contract or another external wallet
|
92
|
+
uint256 allowance = _token.allowance(currentWallet, address(this));
|
93
|
+
if (allowance < currentBalance) {
|
94
|
+
revert ErrorBaseComponentWalletAllowanceTooSmall(currentWallet, newWallet, allowance, currentBalance);
|
95
|
+
}
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
// effects
|
100
|
+
_wallet = newWallet;
|
101
|
+
emit LogBaseComponentWalletAddressChanged(newWallet);
|
102
|
+
|
103
|
+
// interactions
|
104
|
+
if (currentBalance > 0) {
|
105
|
+
// transfer tokens from current wallet to new wallet
|
106
|
+
if (currentWallet == address(this)) {
|
107
|
+
// transferFrom requires self allowance too
|
108
|
+
_token.approve(address(this), currentBalance);
|
109
|
+
}
|
110
|
+
|
111
|
+
SafeERC20.safeTransferFrom(_token, currentWallet, newWallet, currentBalance);
|
112
|
+
emit LogBaseComponentWalletTokensTransferred(currentWallet, newWallet, currentBalance);
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
75
116
|
function getToken() public view override returns (IERC20Metadata token) {
|
76
117
|
return _token;
|
77
118
|
}
|
@@ -8,6 +8,11 @@ import {IInstance} from "../instance/IInstance.sol";
|
|
8
8
|
import {NftId} from "../types/NftId.sol";
|
9
9
|
|
10
10
|
interface IBaseComponent is IRegisterable {
|
11
|
+
error ErrorBaseComponentWalletAddressIsSameAsCurrent(address newWallet);
|
12
|
+
error ErrorBaseComponentWalletAllowanceTooSmall(address oldWallet, address newWallet, uint256 allowance, uint256 balance);
|
13
|
+
|
14
|
+
event LogBaseComponentWalletAddressChanged(address newWallet);
|
15
|
+
event LogBaseComponentWalletTokensTransferred(address from, address to, uint256 amount);
|
11
16
|
|
12
17
|
function lock() external;
|
13
18
|
|
@@ -15,6 +20,7 @@ interface IBaseComponent is IRegisterable {
|
|
15
20
|
|
16
21
|
function getToken() external view returns (IERC20Metadata token);
|
17
22
|
|
23
|
+
function setWallet(address walletAddress) external;
|
18
24
|
function getWallet() external view returns (address walletAddress);
|
19
25
|
|
20
26
|
function getInstance() external view returns (IInstance instance);
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.20;
|
3
|
+
|
4
|
+
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
|
5
|
+
|
6
|
+
|
7
|
+
contract AccessManagerUpgradeableInitializeable is AccessManagerUpgradeable {
|
8
|
+
|
9
|
+
bool private _initialized;
|
10
|
+
|
11
|
+
function __AccessManagerUpgradeableInitializeable_init(address initialAdmin) public {
|
12
|
+
require(!_initialized, "AccessManager: already initialized");
|
13
|
+
|
14
|
+
if (initialAdmin == address(0)) {
|
15
|
+
revert AccessManagerInvalidInitialAdmin(address(0));
|
16
|
+
}
|
17
|
+
|
18
|
+
// admin is active immediately and without any execution delay.
|
19
|
+
_grantRole(ADMIN_ROLE, initialAdmin, 0, 0);
|
20
|
+
_initialized = true;
|
21
|
+
}
|
22
|
+
|
23
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.20;
|
3
|
+
|
4
|
+
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
|
5
|
+
|
6
|
+
import {BundleManager} from "./BundleManager.sol";
|
7
|
+
import {InstanceReader} from "./InstanceReader.sol";
|
8
|
+
|
9
|
+
import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
|
10
|
+
import {IDistributionService} from "./service/IDistributionService.sol";
|
11
|
+
import {IPoolService} from "./service/IPoolService.sol";
|
12
|
+
import {IProductService} from "./service/IProductService.sol";
|
13
|
+
import {IBundle} from "./module/IBundle.sol";
|
14
|
+
import {ISetup} from "./module/ISetup.sol";
|
15
|
+
import {NftId} from "../types/NftId.sol";
|
16
|
+
import {StateId} from "../types/StateId.sol";
|
17
|
+
import {RiskId} from "../types/RiskId.sol";
|
18
|
+
import {IRisk} from "./module/IRisk.sol";
|
19
|
+
import {IPolicy} from "./module/IPolicy.sol";
|
20
|
+
import {IKeyValueStore} from "./base/IKeyValueStore.sol";
|
21
|
+
|
22
|
+
|
23
|
+
interface IInstanceBase is IERC165, IKeyValueStore {
|
24
|
+
|
25
|
+
|
26
|
+
}
|
@@ -10,7 +10,7 @@ import {IRegistry} from "../registry/IRegistry.sol";
|
|
10
10
|
import {IRegisterable} from "../shared/IRegisterable.sol";
|
11
11
|
import {IBaseComponent} from "../components/IBaseComponent.sol";
|
12
12
|
|
13
|
-
import {
|
13
|
+
import {AccessManagerUpgradeableInitializeable} from "./AccessManagerUpgradeableInitializeable.sol";
|
14
14
|
import {Instance} from "./Instance.sol";
|
15
15
|
import {InstanceReader} from "./InstanceReader.sol";
|
16
16
|
import {BundleManager} from "./BundleManager.sol";
|
@@ -22,7 +22,7 @@ interface IInstanceService is IService {
|
|
22
22
|
function createInstanceClone()
|
23
23
|
external
|
24
24
|
returns (
|
25
|
-
|
25
|
+
AccessManagerUpgradeableInitializeable clonedAccessManager,
|
26
26
|
Instance clonedInstance,
|
27
27
|
NftId instanceNftId,
|
28
28
|
InstanceReader clonedInstanceReader,
|
@@ -3,9 +3,10 @@ pragma solidity ^0.8.20;
|
|
3
3
|
|
4
4
|
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
5
5
|
import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
|
6
|
+
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
|
7
|
+
import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
|
8
|
+
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
|
6
9
|
|
7
|
-
import {AccessManagedSimple} from "./AccessManagedSimple.sol";
|
8
|
-
import {AccessManagerSimple} from "./AccessManagerSimple.sol";
|
9
10
|
import {IAccess} from "./module/IAccess.sol";
|
10
11
|
import {IBundle} from "./module/IBundle.sol";
|
11
12
|
import {IPolicy} from "./module/IPolicy.sol";
|
@@ -30,13 +31,13 @@ import {IDistributionService} from "./service/IDistributionService.sol";
|
|
30
31
|
import {IPoolService} from "./service/IPoolService.sol";
|
31
32
|
import {IProductService} from "./service/IProductService.sol";
|
32
33
|
import {VersionPart} from "../types/Version.sol";
|
34
|
+
import {InstanceBase} from "./InstanceBase.sol";
|
33
35
|
|
34
36
|
contract Instance is
|
35
|
-
|
36
|
-
KeyValueStore,
|
37
|
+
AccessManagedUpgradeable,
|
37
38
|
IInstance,
|
38
|
-
|
39
|
-
|
39
|
+
// Initializable,
|
40
|
+
InstanceBase
|
40
41
|
{
|
41
42
|
|
42
43
|
uint64 public constant ADMIN_ROLE = type(uint64).min;
|
@@ -53,21 +54,19 @@ contract Instance is
|
|
53
54
|
|
54
55
|
mapping(ShortString name => address target) internal _target;
|
55
56
|
|
56
|
-
|
57
|
+
AccessManagerUpgradeable internal _accessManager;
|
57
58
|
InstanceReader internal _instanceReader;
|
58
59
|
BundleManager internal _bundleManager;
|
59
60
|
|
60
|
-
|
61
|
+
function initialize(address accessManagerAddress, address registryAddress, NftId registryNftId, address initialOwner)
|
62
|
+
public
|
63
|
+
initializer
|
61
64
|
{
|
62
|
-
initialize(accessManagerAddress, registryAddress, registryNftId, msg.sender);
|
63
|
-
}
|
64
|
-
|
65
|
-
function initialize(address accessManagerAddress, address registryAddress, NftId registryNftId, address initialOwner) public {
|
66
65
|
require(!_initialized, "Contract instance has already been initialized");
|
67
66
|
|
68
|
-
|
67
|
+
__AccessManaged_init(accessManagerAddress);
|
69
68
|
|
70
|
-
_accessManager =
|
69
|
+
_accessManager = AccessManagerUpgradeable(accessManagerAddress);
|
71
70
|
_createRole(RoleIdLib.toRoleId(ADMIN_ROLE), "AdminRole", false, false);
|
72
71
|
_createRole(RoleIdLib.toRoleId(PUBLIC_ROLE), "PublicRole", false, false);
|
73
72
|
|
@@ -436,6 +435,7 @@ contract Instance is
|
|
436
435
|
|
437
436
|
function setInstanceReader(InstanceReader instanceReader) external restricted() {
|
438
437
|
require(address(_instanceReader) == address(0), "InstanceReader is set");
|
438
|
+
require(instanceReader.getInstanceNftId() == getNftId(), "NFT ID of InstanceReader does not match");
|
439
439
|
_instanceReader = instanceReader;
|
440
440
|
}
|
441
441
|
|
@@ -445,6 +445,7 @@ contract Instance is
|
|
445
445
|
|
446
446
|
function setBundleManager(BundleManager bundleManager) external restricted() {
|
447
447
|
require(address(_bundleManager) == address(0), "BundleManager is set");
|
448
|
+
require(bundleManager.getInstanceNftId() == getNftId(), "NFT ID of BundleManager does not match");
|
448
449
|
_bundleManager = bundleManager;
|
449
450
|
}
|
450
451
|
|
@@ -3,9 +3,9 @@ pragma solidity ^0.8.20;
|
|
3
3
|
|
4
4
|
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
5
5
|
import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
|
6
|
+
import {AccessManagedUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagedUpgradeable.sol";
|
7
|
+
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
|
6
8
|
|
7
|
-
import {AccessManagedSimple} from "./AccessManagedSimple.sol";
|
8
|
-
import {AccessManagerSimple} from "./AccessManagerSimple.sol";
|
9
9
|
import {IBundle} from "./module/IBundle.sol";
|
10
10
|
import {IPolicy} from "./module/IPolicy.sol";
|
11
11
|
import {IRisk} from "./module/IRisk.sol";
|
@@ -21,7 +21,7 @@ import {StateId, ACTIVE} from "../types/StateId.sol";
|
|
21
21
|
import {Timestamp, TimestampLib} from "../types/Timestamp.sol";
|
22
22
|
|
23
23
|
contract InstanceAccessManager is
|
24
|
-
|
24
|
+
AccessManagedUpgradeable
|
25
25
|
{
|
26
26
|
string public constant ADMIN_ROLE_NAME = "AdminRole";
|
27
27
|
string public constant PUBLIC_ROLE_NAME = "PublicRole";
|
@@ -76,12 +76,12 @@ contract InstanceAccessManager is
|
|
76
76
|
mapping(ShortString name => address target) internal _targetForName;
|
77
77
|
address [] internal _targets;
|
78
78
|
|
79
|
-
|
79
|
+
AccessManagerUpgradeable internal _accessManager;
|
80
80
|
|
81
81
|
constructor(address accessManager)
|
82
82
|
{
|
83
|
-
_accessManager =
|
84
|
-
|
83
|
+
_accessManager = AccessManagerUpgradeable(accessManager);
|
84
|
+
__AccessManaged_init(accessManager);
|
85
85
|
|
86
86
|
_createRole(RoleIdLib.toRoleId(_accessManager.ADMIN_ROLE()), ADMIN_ROLE_NAME, false, false);
|
87
87
|
_createRole(RoleIdLib.toRoleId(_accessManager.PUBLIC_ROLE()), PUBLIC_ROLE_NAME, false, false);
|
@@ -0,0 +1,41 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.20;
|
3
|
+
|
4
|
+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
|
5
|
+
import {ShortString, ShortStrings} from "@openzeppelin/contracts/utils/ShortStrings.sol";
|
6
|
+
|
7
|
+
import {IAccess} from "./module/IAccess.sol";
|
8
|
+
import {IBundle} from "./module/IBundle.sol";
|
9
|
+
import {IPolicy} from "./module/IPolicy.sol";
|
10
|
+
import {IRisk} from "./module/IRisk.sol";
|
11
|
+
import {ISetup} from "./module/ISetup.sol";
|
12
|
+
import {Key32, KeyId, Key32Lib} from "../types/Key32.sol";
|
13
|
+
import {KeyValueStore} from "./base/KeyValueStore.sol";
|
14
|
+
import {IInstance} from "./IInstance.sol";
|
15
|
+
import {InstanceReader} from "./InstanceReader.sol";
|
16
|
+
import {BundleManager} from "./BundleManager.sol";
|
17
|
+
import {NftId} from "../types/NftId.sol";
|
18
|
+
import {NumberId} from "../types/NumberId.sol";
|
19
|
+
import {ObjectType, BUNDLE, DISTRIBUTION, INSTANCE, POLICY, POOL, ROLE, PRODUCT, TARGET} from "../types/ObjectType.sol";
|
20
|
+
import {RiskId, RiskIdLib} from "../types/RiskId.sol";
|
21
|
+
import {RoleId, RoleIdLib} from "../types/RoleId.sol";
|
22
|
+
import {StateId, ACTIVE} from "../types/StateId.sol";
|
23
|
+
import {ERC165} from "../shared/ERC165.sol";
|
24
|
+
import {Registerable} from "../shared/Registerable.sol";
|
25
|
+
import {ComponentOwnerService} from "./service/ComponentOwnerService.sol";
|
26
|
+
import {IComponentOwnerService} from "./service/IComponentOwnerService.sol";
|
27
|
+
import {IDistributionService} from "./service/IDistributionService.sol";
|
28
|
+
import {IPoolService} from "./service/IPoolService.sol";
|
29
|
+
import {IProductService} from "./service/IProductService.sol";
|
30
|
+
import {VersionPart} from "../types/Version.sol";
|
31
|
+
import {IInstanceBase} from "./IInstanceBase.sol";
|
32
|
+
|
33
|
+
contract InstanceBase is
|
34
|
+
IInstanceBase,
|
35
|
+
KeyValueStore,
|
36
|
+
ERC165,
|
37
|
+
Registerable
|
38
|
+
{
|
39
|
+
|
40
|
+
|
41
|
+
}
|
@@ -2,8 +2,9 @@
|
|
2
2
|
pragma solidity ^0.8.20;
|
3
3
|
|
4
4
|
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
|
5
|
+
import {AccessManagerUpgradeable} from "@openzeppelin/contracts-upgradeable/access/manager/AccessManagerUpgradeable.sol";
|
5
6
|
|
6
|
-
import {
|
7
|
+
import {AccessManagerUpgradeableInitializeable} from "./AccessManagerUpgradeableInitializeable.sol";
|
7
8
|
import {InstanceAccessManager} from "./InstanceAccessManager.sol";
|
8
9
|
import {Instance} from "./Instance.sol";
|
9
10
|
import {IInstanceService} from "./IInstanceService.sol";
|
@@ -35,7 +36,7 @@ contract InstanceService is Service, IInstanceService {
|
|
35
36
|
function createInstanceClone()
|
36
37
|
external
|
37
38
|
returns (
|
38
|
-
|
39
|
+
AccessManagerUpgradeableInitializeable clonedAccessManager,
|
39
40
|
Instance clonedInstance,
|
40
41
|
NftId clonedInstanceNftId,
|
41
42
|
InstanceReader clonedInstanceReader,
|
@@ -51,8 +52,8 @@ contract InstanceService is Service, IInstanceService {
|
|
51
52
|
// initially set the authority of the access managar to this (being the instance service).
|
52
53
|
// This will allow the instance service to bootstrap the authorizations of the instance
|
53
54
|
// and then transfer the ownership of the access manager to the instance owner once everything is setup
|
54
|
-
clonedAccessManager =
|
55
|
-
clonedAccessManager.
|
55
|
+
clonedAccessManager = AccessManagerUpgradeableInitializeable(Clones.clone(_accessManagerMaster));
|
56
|
+
clonedAccessManager.__AccessManagerUpgradeableInitializeable_init(address(this));
|
56
57
|
|
57
58
|
clonedInstance = Instance(Clones.clone(_instanceMaster));
|
58
59
|
clonedInstance.initialize(address(clonedAccessManager), _registryAddress, registryNftId, msg.sender);
|
@@ -79,7 +80,7 @@ contract InstanceService is Service, IInstanceService {
|
|
79
80
|
emit LogInstanceCloned(address(clonedAccessManager), address(clonedInstance), address(clonedInstanceReader), clonedInstanceNftId);
|
80
81
|
}
|
81
82
|
|
82
|
-
function _grantInitialAuthorizations(
|
83
|
+
function _grantInitialAuthorizations(AccessManagerUpgradeable clonedAccessManager, Instance clonedInstance, BundleManager clonedBundleManager) internal {
|
83
84
|
// configure authorization for distribution service on instance
|
84
85
|
address distributionServiceAddress = _registry.getServiceAddress("DistributionService", VersionLib.toVersion(3, 0, 0).toMajorPart());
|
85
86
|
clonedAccessManager.grantRole(DISTRIBUTION_SERVICE_ROLE().toInt(), distributionServiceAddress, 0);
|
@@ -142,20 +143,26 @@ contract InstanceService is Service, IInstanceService {
|
|
142
143
|
}
|
143
144
|
|
144
145
|
function setInstanceMaster(address instanceMaster) external {
|
146
|
+
// TODO: ensure instance has correct access manager
|
145
147
|
require(
|
146
148
|
_instanceMaster == address(0),
|
147
149
|
"ERROR:CRD-002:INSTANCE_MASTER_ALREADY_SET");
|
148
150
|
_instanceMaster = instanceMaster;
|
149
151
|
}
|
150
152
|
|
151
|
-
function setInstanceReaderMaster(address instanceReaderMaster) external {
|
152
|
-
|
153
|
-
|
154
|
-
"ERROR:CRD-003:INSTANCE_READER_MASTER_ALREADY_SET");
|
153
|
+
function setInstanceReaderMaster(address instanceReaderMaster) external onlyOwner {
|
154
|
+
// TODO: ensure instance reader points to master instance
|
155
|
+
// TODO: add a test for this
|
155
156
|
_instanceReaderMaster = instanceReaderMaster;
|
156
157
|
}
|
157
158
|
|
159
|
+
function upgradeInstanceReader(NftId instanceNftId) external {
|
160
|
+
// TODO: ensure this is done by instance owner
|
161
|
+
// TODO: upgrade instance reader of this instance to latest (set above here)
|
162
|
+
}
|
163
|
+
|
158
164
|
function setBundleManagerMaster(address bundleManagerMaster) external {
|
165
|
+
// TODO: ensure bundle manager points to master instance
|
159
166
|
require(
|
160
167
|
_instanceBundleManagerMaster == address(0),
|
161
168
|
"ERROR:CRD-004:BUNDLE_MANAGER_MASTER_ALREADY_SET");
|
@@ -221,7 +228,7 @@ contract InstanceService is Service, IInstanceService {
|
|
221
228
|
IRegistry.ObjectInfo memory instanceObjectInfo = getRegistry().getObjectInfo(instanceNftId);
|
222
229
|
address instanceAddress = instanceObjectInfo.objectAddress;
|
223
230
|
Instance instance = Instance(instanceAddress);
|
224
|
-
|
231
|
+
AccessManagerUpgradeable accessManager = AccessManagerUpgradeable(instance.authority());
|
225
232
|
(bool isMember, uint32 executionDelay) = accessManager.hasRole(role.toInt(), account);
|
226
233
|
if (executionDelay > 0) {
|
227
234
|
return false;
|