@etherisc/gif-next 0.0.2-ebbe63d → 0.0.2-f824182-503
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +120 -1
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +4 -0
- package/artifacts/contracts/components/Component.sol/Component.json +205 -0
- package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +4 -0
- package/artifacts/contracts/components/Component.sol/InstanceLinked.json +35 -0
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +4 -0
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +255 -0
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.dbg.json +4 -0
- package/artifacts/contracts/components/IProduct.sol/IProductComponent.json +74 -0
- package/artifacts/contracts/components/Pool.sol/Pool.dbg.json +4 -0
- package/artifacts/contracts/components/Pool.sol/Pool.json +328 -0
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +4 -0
- package/artifacts/contracts/components/Product.sol/Product.json +346 -0
- 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 +4 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/A.json +128 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +42 -0
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/B.sol/B.json +76 -0
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/C.sol/C.json +89 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.json +128 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.json +37 -0
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.json +50 -0
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +4 -0
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.json +63 -0
- 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 +4 -0
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +10 -0
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +4 -0
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +10 -0
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +4 -0
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +1479 -0
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +4 -0
- package/artifacts/contracts/instance/Instance.sol/Instance.json +1725 -0
- package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +4 -0
- package/artifacts/contracts/instance/access/Access.sol/AccessModule.json +400 -0
- package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +4 -0
- package/artifacts/contracts/instance/access/IAccess.sol/IAccess.json +10 -0
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +4 -0
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.json +35 -0
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +4 -0
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.json +50 -0
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +4 -0
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.json +336 -0
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +4 -0
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +299 -0
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +4 -0
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +202 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +4 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IComponent.json +10 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +4 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +205 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +4 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +217 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +4 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +141 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +4 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.json +24 -0
- 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 +4 -0
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.json +10 -0
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +4 -0
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.json +254 -0
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +4 -0
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.json +254 -0
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +4 -0
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.json +10 -0
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +4 -0
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.json +129 -0
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +4 -0
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.json +155 -0
- package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +4 -0
- package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.json +75 -0
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +4 -0
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.json +127 -0
- package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +4 -0
- package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.json +75 -0
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +4 -0
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +196 -0
- 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 +4 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +534 -0
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +4 -0
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.json +452 -0
- package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +4 -0
- package/artifacts/contracts/registry/IRegistry.sol/IOwnable.json +24 -0
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +4 -0
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.json +166 -0
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +4 -0
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.json +188 -0
- package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +4 -0
- package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.json +49 -0
- package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +4 -0
- package/artifacts/contracts/registry/Registry.sol/Registerable.json +166 -0
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +4 -0
- package/artifacts/contracts/registry/Registry.sol/Registry.json +256 -0
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +4 -0
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +60 -0
- 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 +4 -0
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +10 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +4 -0
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +92 -0
- 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 +77 -0
- package/contracts/components/IPool.sol +15 -0
- package/contracts/components/IProduct.sol +16 -0
- package/contracts/components/Pool.sol +52 -0
- package/contracts/components/Product.sol +89 -0
- package/contracts/experiment/errors/Require.sol +38 -0
- package/contracts/experiment/errors/Revert.sol +44 -0
- package/contracts/experiment/inheritance/A.sol +53 -0
- package/contracts/experiment/inheritance/B.sol +28 -0
- package/contracts/experiment/inheritance/C.sol +34 -0
- package/contracts/experiment/inheritance/IA.sol +13 -0
- package/contracts/experiment/inheritance/IB.sol +10 -0
- package/contracts/experiment/inheritance/IC.sol +12 -0
- 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 +47 -0
- package/contracts/experiment/types/TypeB.sol +29 -0
- package/contracts/instance/IInstance.sol +25 -0
- package/contracts/instance/Instance.sol +72 -0
- package/contracts/instance/access/Access.sol +165 -0
- package/contracts/instance/access/IAccess.sol +63 -0
- package/contracts/instance/component/ComponentModule.sol +274 -0
- package/contracts/instance/component/IComponent.sol +74 -0
- package/contracts/instance/lifecycle/ILifecycle.sol +47 -0
- package/contracts/instance/lifecycle/LifecycleModule.sol +88 -0
- package/contracts/instance/policy/IPolicy.sol +50 -0
- package/contracts/instance/policy/PolicyModule.sol +114 -0
- package/contracts/instance/pool/IPoolModule.sol +23 -0
- package/contracts/instance/pool/PoolModule.sol +81 -0
- package/contracts/instance/product/IProductService.sol +36 -0
- package/contracts/instance/product/ProductService.sol +136 -0
- 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 +135 -0
- package/contracts/registry/IChainNft.sol +21 -0
- package/contracts/registry/IRegistry.sol +67 -0
- package/contracts/registry/Registry.sol +182 -0
- package/contracts/types/Blocknumber.sol +118 -0
- package/contracts/types/ChainId.sol +38 -0
- package/contracts/types/Fee.sol +32 -0
- package/contracts/types/NftId.sol +51 -0
- 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 +15 -8
- package/artifacts/contracts/Dip.sol/DIP.dbg.json +0 -4
- package/artifacts/contracts/Dip.sol/DIP.json +0 -338
- package/artifacts/contracts/Lock.sol/Lock.dbg.json +0 -4
- package/artifacts/contracts/Lock.sol/Lock.json +0 -74
- package/contracts/Dip.sol +0 -26
- package/contracts/Lock.sol +0 -34
@@ -0,0 +1,168 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
5
|
+
|
6
|
+
import {NftId} from "../../types/NftId.sol";
|
7
|
+
import {Fee, feeIsZero} from "../../types/Fee.sol";
|
8
|
+
import {UFixed, UFixedMathLib} from "../../types/UFixed.sol";
|
9
|
+
import {IProductComponent} from "../../components/IProduct.sol";
|
10
|
+
import {IPolicy, IPolicyModule} from "../policy/IPolicy.sol";
|
11
|
+
import {TokenHandler} from "./TokenHandler.sol";
|
12
|
+
import {ITreasuryModule} from "./ITreasury.sol";
|
13
|
+
import {TokenHandler} from "./TokenHandler.sol";
|
14
|
+
|
15
|
+
abstract contract TreasuryModule is ITreasuryModule {
|
16
|
+
mapping(NftId productNftId => ProductSetup setup) private _productSetup;
|
17
|
+
mapping(NftId distributorNftId => DistributorSetup setup)
|
18
|
+
private _distributorSetup;
|
19
|
+
mapping(NftId poolNftId => PoolSetup setup) private _poolSetup;
|
20
|
+
|
21
|
+
IPolicyModule private _policyModule;
|
22
|
+
|
23
|
+
constructor() {
|
24
|
+
_policyModule = IPolicyModule(address(this));
|
25
|
+
}
|
26
|
+
|
27
|
+
function registerProduct(
|
28
|
+
NftId productNftId,
|
29
|
+
NftId distributorNftId,
|
30
|
+
NftId poolNftId,
|
31
|
+
IERC20 token,
|
32
|
+
address wallet,
|
33
|
+
Fee memory policyFee,
|
34
|
+
Fee memory processingFee
|
35
|
+
) external override // TODO add authz (only component module)
|
36
|
+
{
|
37
|
+
// TODO add validation
|
38
|
+
|
39
|
+
// deploy product specific handler contract
|
40
|
+
TokenHandler tokenHandler = new TokenHandler(address(token));
|
41
|
+
|
42
|
+
_productSetup[productNftId] = ProductSetup(
|
43
|
+
productNftId,
|
44
|
+
distributorNftId,
|
45
|
+
poolNftId,
|
46
|
+
token,
|
47
|
+
tokenHandler,
|
48
|
+
wallet,
|
49
|
+
policyFee,
|
50
|
+
processingFee
|
51
|
+
);
|
52
|
+
|
53
|
+
// TODO add logging
|
54
|
+
}
|
55
|
+
|
56
|
+
function setProductFees(
|
57
|
+
NftId productNftId,
|
58
|
+
Fee memory policyFee,
|
59
|
+
Fee memory processingFee
|
60
|
+
) external override // TODO add authz (only component owner service)
|
61
|
+
{
|
62
|
+
// TODO add validation
|
63
|
+
|
64
|
+
ProductSetup storage setup = _productSetup[productNftId];
|
65
|
+
setup.policyFee = policyFee;
|
66
|
+
setup.processingFee = processingFee;
|
67
|
+
|
68
|
+
// TODO add logging
|
69
|
+
}
|
70
|
+
|
71
|
+
function registerPool(
|
72
|
+
NftId poolNftId,
|
73
|
+
address wallet,
|
74
|
+
Fee memory stakingFee,
|
75
|
+
Fee memory performanceFee
|
76
|
+
) external override // TODO add authz (only component module)
|
77
|
+
{
|
78
|
+
// TODO add validation
|
79
|
+
|
80
|
+
_poolSetup[poolNftId] = PoolSetup(
|
81
|
+
poolNftId,
|
82
|
+
wallet,
|
83
|
+
stakingFee,
|
84
|
+
performanceFee
|
85
|
+
);
|
86
|
+
|
87
|
+
// TODO add logging
|
88
|
+
}
|
89
|
+
|
90
|
+
function setPoolFees(
|
91
|
+
NftId poolNftId,
|
92
|
+
Fee memory stakingFee,
|
93
|
+
Fee memory performanceFee
|
94
|
+
) external override // TODO add authz (only component owner service)
|
95
|
+
{
|
96
|
+
// TODO add validation
|
97
|
+
|
98
|
+
PoolSetup storage setup = _poolSetup[poolNftId];
|
99
|
+
setup.stakingFee = stakingFee;
|
100
|
+
setup.performanceFee = performanceFee;
|
101
|
+
|
102
|
+
// TODO add logging
|
103
|
+
}
|
104
|
+
|
105
|
+
function getTokenHandler(
|
106
|
+
NftId productNftId
|
107
|
+
) external view override returns (TokenHandler tokenHandler) {
|
108
|
+
return _productSetup[productNftId].tokenHandler;
|
109
|
+
}
|
110
|
+
|
111
|
+
function getProductSetup(
|
112
|
+
NftId productNftId
|
113
|
+
) external view override returns (ProductSetup memory setup) {
|
114
|
+
return _productSetup[productNftId];
|
115
|
+
}
|
116
|
+
|
117
|
+
function getPoolSetup(
|
118
|
+
NftId poolNftId
|
119
|
+
) external view override returns (PoolSetup memory setup) {
|
120
|
+
return _poolSetup[poolNftId];
|
121
|
+
}
|
122
|
+
|
123
|
+
function processPremium(
|
124
|
+
NftId policyNftId,
|
125
|
+
NftId productNftId
|
126
|
+
) external override // TODO add authz (only product service)
|
127
|
+
{
|
128
|
+
IPolicy.PolicyInfo memory policyInfo = _policyModule.getPolicyInfo(
|
129
|
+
policyNftId
|
130
|
+
);
|
131
|
+
require(
|
132
|
+
policyInfo.nftId == policyNftId,
|
133
|
+
"ERROR:TRS-020:POLICY_UNKNOWN"
|
134
|
+
);
|
135
|
+
|
136
|
+
ProductSetup memory product = _productSetup[productNftId];
|
137
|
+
TokenHandler tokenHandler = product.tokenHandler;
|
138
|
+
address policyOwner = this.getRegistry().getOwner(policyNftId);
|
139
|
+
address poolWallet = _poolSetup[product.poolNftId].wallet;
|
140
|
+
// TODO add validation
|
141
|
+
|
142
|
+
if (feeIsZero(product.policyFee)) {
|
143
|
+
tokenHandler.transfer(
|
144
|
+
policyOwner,
|
145
|
+
poolWallet,
|
146
|
+
policyInfo.premiumAmount
|
147
|
+
);
|
148
|
+
} else {
|
149
|
+
(uint256 feeAmount, uint256 netAmount) = calculateFeeAmount(
|
150
|
+
policyInfo.premiumAmount,
|
151
|
+
product.policyFee
|
152
|
+
);
|
153
|
+
|
154
|
+
tokenHandler.transfer(policyOwner, product.wallet, feeAmount);
|
155
|
+
tokenHandler.transfer(policyOwner, poolWallet, netAmount);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
function calculateFeeAmount(
|
160
|
+
uint256 amount,
|
161
|
+
Fee memory fee
|
162
|
+
) public pure override returns (uint256 feeAmount, uint256 netAmount) {
|
163
|
+
UFixed fractionalAmount = UFixedMathLib.itof(amount) *
|
164
|
+
fee.fractionalFee;
|
165
|
+
feeAmount = UFixedMathLib.ftoi(fractionalAmount) + fee.fixedFee;
|
166
|
+
netAmount = amount - feeAmount;
|
167
|
+
}
|
168
|
+
}
|
@@ -0,0 +1,135 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {ERC721, ERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
|
5
|
+
import {IChainNft} from "./IChainNft.sol";
|
6
|
+
|
7
|
+
contract ChainNft is ERC721Enumerable, IChainNft {
|
8
|
+
string public constant NAME = "Dezentralized Insurance Protocol Registry";
|
9
|
+
string public constant SYMBOL = "DIPR";
|
10
|
+
|
11
|
+
// remember token uri
|
12
|
+
mapping(uint256 tokenId => string uri) private _uri;
|
13
|
+
|
14
|
+
// remember registry
|
15
|
+
address private _registry;
|
16
|
+
|
17
|
+
// only used for _getNextTokenId
|
18
|
+
uint256 internal _chainIdInt;
|
19
|
+
uint256 internal _chainIdDigits;
|
20
|
+
uint256 internal _chainIdMultiplier;
|
21
|
+
uint256 internal _idNext;
|
22
|
+
uint256 internal _totalMinted;
|
23
|
+
|
24
|
+
modifier onlyRegistry() {
|
25
|
+
require(msg.sender == _registry, "ERROR:NFT-001:CALLER_NOT_REGISTRY");
|
26
|
+
_;
|
27
|
+
}
|
28
|
+
|
29
|
+
constructor(address registry) ERC721(NAME, SYMBOL) {
|
30
|
+
require(registry != address(0), "ERROR:NFT-010:REGISTRY_ZERO");
|
31
|
+
|
32
|
+
_registry = registry;
|
33
|
+
|
34
|
+
_chainIdInt = block.chainid;
|
35
|
+
_chainIdDigits = _countDigits(_chainIdInt);
|
36
|
+
_chainIdMultiplier = 10 ** _chainIdDigits;
|
37
|
+
|
38
|
+
// on mainnet/goerli start /1 (reserved for protocol nft) on other chains with 2
|
39
|
+
if (block.chainid == 1 || block.chainid == 5) {
|
40
|
+
_idNext = 1;
|
41
|
+
} else {
|
42
|
+
_idNext = 2;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
function mint(
|
47
|
+
address to,
|
48
|
+
string memory uri
|
49
|
+
) external override onlyRegistry returns (uint256 tokenId) {
|
50
|
+
tokenId = _getNextTokenId();
|
51
|
+
_totalMinted++;
|
52
|
+
|
53
|
+
_safeMint(to, tokenId);
|
54
|
+
|
55
|
+
if (bytes(uri).length > 0) {
|
56
|
+
_uri[tokenId] = uri;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
function burn(uint256 tokenId) external override onlyRegistry {
|
61
|
+
_requireMinted(tokenId);
|
62
|
+
_burn(tokenId);
|
63
|
+
delete _uri[tokenId];
|
64
|
+
}
|
65
|
+
|
66
|
+
function setURI(
|
67
|
+
uint256 tokenId,
|
68
|
+
string memory uri
|
69
|
+
) external override onlyRegistry {
|
70
|
+
require(bytes(uri).length > 0, "ERROR:CRG-011:URI_EMPTY");
|
71
|
+
|
72
|
+
_requireMinted(tokenId);
|
73
|
+
_uri[tokenId] = uri;
|
74
|
+
}
|
75
|
+
|
76
|
+
function exists(uint256 tokenId) external view override returns (bool) {
|
77
|
+
return _exists(tokenId);
|
78
|
+
}
|
79
|
+
|
80
|
+
function tokenURI(
|
81
|
+
uint256 tokenId
|
82
|
+
) public view override returns (string memory) {
|
83
|
+
_requireMinted(tokenId);
|
84
|
+
return _uri[tokenId];
|
85
|
+
}
|
86
|
+
|
87
|
+
function getRegistryAddress() external view override returns (address) {
|
88
|
+
return _registry;
|
89
|
+
}
|
90
|
+
|
91
|
+
function totalMinted() external view override returns (uint256) {
|
92
|
+
return _totalMinted;
|
93
|
+
}
|
94
|
+
|
95
|
+
// requirement: each chain registry produces token ids that
|
96
|
+
// are guaranteed to not collide with any token id genereated
|
97
|
+
// on a different chain
|
98
|
+
//
|
99
|
+
// format concat(counter,chainid,2 digits for len-of-chain-id)
|
100
|
+
// restriction chainid up to 99 digits
|
101
|
+
// decode: from right to left:
|
102
|
+
// - 2 right most digits encode length of chainid
|
103
|
+
// - move number of digits to left as determined above (-> chainid)
|
104
|
+
// - the reminder to the left is the counter
|
105
|
+
// examples
|
106
|
+
// 1101
|
107
|
+
// ^^ ^
|
108
|
+
// || +- 1-digit chain id
|
109
|
+
// |+-- chain id = 1 (mainnet)
|
110
|
+
// +-- 1st token id on mainnet
|
111
|
+
// (1 * 10 ** 1 + 1) * 100 + 1
|
112
|
+
// 42987654321010
|
113
|
+
// ^ ^ ^
|
114
|
+
// | | +- 10-digit chain id
|
115
|
+
// | +-- chain id = 9876543210 (hypothetical chainid)
|
116
|
+
// +-- 42nd token id on this chain
|
117
|
+
// (42 * 10 ** 10 + 9876543210) * 100 + 10
|
118
|
+
// (index * 10 ** digits + chainid) * 100 + digits (1 < digits < 100)
|
119
|
+
|
120
|
+
function _getNextTokenId() private returns (uint256 id) {
|
121
|
+
id =
|
122
|
+
(_idNext * _chainIdMultiplier + _chainIdInt) *
|
123
|
+
100 +
|
124
|
+
_chainIdDigits;
|
125
|
+
_idNext++;
|
126
|
+
}
|
127
|
+
|
128
|
+
function _countDigits(uint256 num) private pure returns (uint256 count) {
|
129
|
+
count = 0;
|
130
|
+
while (num != 0) {
|
131
|
+
count++;
|
132
|
+
num /= 10;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {IERC721Enumerable} from "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
|
5
|
+
|
6
|
+
interface IChainNft is IERC721Enumerable {
|
7
|
+
function mint(
|
8
|
+
address to,
|
9
|
+
string memory uri
|
10
|
+
) external returns (uint256 tokenId);
|
11
|
+
|
12
|
+
function burn(uint256 tokenId) external;
|
13
|
+
|
14
|
+
function setURI(uint256 tokenId, string memory uri) external;
|
15
|
+
|
16
|
+
function exists(uint256 tokenId) external view returns (bool);
|
17
|
+
|
18
|
+
function totalMinted() external view returns (uint256);
|
19
|
+
|
20
|
+
function getRegistryAddress() external view returns (address registry);
|
21
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {NftId} from "../types/NftId.sol";
|
5
|
+
import {ObjectType} from "../types/ObjectType.sol";
|
6
|
+
|
7
|
+
interface IOwnable {
|
8
|
+
function getOwner() external view returns (address owner);
|
9
|
+
}
|
10
|
+
|
11
|
+
interface IRegistryLinked {
|
12
|
+
event LogDebug(uint256 idx, address module, string comment);
|
13
|
+
|
14
|
+
function getRegistry() external view returns (IRegistry registry);
|
15
|
+
}
|
16
|
+
|
17
|
+
interface IRegisterable is IOwnable, IRegistryLinked {
|
18
|
+
function register() external returns (NftId nftId);
|
19
|
+
|
20
|
+
function getNftId() external view returns (NftId nftId);
|
21
|
+
|
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);
|
29
|
+
|
30
|
+
function getInitialOwner() external view returns (address initialOwner);
|
31
|
+
|
32
|
+
function isRegistered() external view returns (bool);
|
33
|
+
}
|
34
|
+
|
35
|
+
interface IRegistry {
|
36
|
+
struct RegistryInfo {
|
37
|
+
NftId nftId;
|
38
|
+
NftId parentNftId;
|
39
|
+
ObjectType objectType;
|
40
|
+
address objectAddress;
|
41
|
+
address initialOwner;
|
42
|
+
}
|
43
|
+
|
44
|
+
function register(address objectAddress) external returns (NftId nftId);
|
45
|
+
|
46
|
+
function registerObjectForInstance(
|
47
|
+
NftId parentNftid,
|
48
|
+
ObjectType objectType,
|
49
|
+
address initialOwner
|
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);
|
57
|
+
|
58
|
+
function getInfo(
|
59
|
+
NftId nftId
|
60
|
+
) external view returns (RegistryInfo memory info);
|
61
|
+
|
62
|
+
function getOwner(NftId nftId) external view returns (address ownerAddress);
|
63
|
+
|
64
|
+
function isRegistered(address objectAddress) external view returns (bool);
|
65
|
+
|
66
|
+
function getNftAddress() external view returns (address nft);
|
67
|
+
}
|
@@ -0,0 +1,182 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {IChainNft} from "./IChainNft.sol";
|
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";
|
8
|
+
|
9
|
+
contract RegistryLinked is IRegistryLinked {
|
10
|
+
IRegistry internal _registry;
|
11
|
+
|
12
|
+
constructor(address registry) {
|
13
|
+
_registry = IRegistry(registry);
|
14
|
+
}
|
15
|
+
|
16
|
+
function getRegistry() external view override returns (IRegistry registry) {
|
17
|
+
return _registry;
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
abstract contract Registerable is RegistryLinked, IRegisterable {
|
22
|
+
using NftIdLib for NftId;
|
23
|
+
|
24
|
+
address private _initialOwner;
|
25
|
+
|
26
|
+
constructor(address registry) RegistryLinked(registry) {
|
27
|
+
_initialOwner = msg.sender;
|
28
|
+
}
|
29
|
+
|
30
|
+
// getType, getData and register need to be implemented by concrete contract
|
31
|
+
|
32
|
+
function isRegisterable() external pure override returns (bool) {
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
|
36
|
+
function getInitialOwner() public view override returns (address deployer) {
|
37
|
+
return _initialOwner;
|
38
|
+
}
|
39
|
+
|
40
|
+
function isRegistered() public view override returns (bool) {
|
41
|
+
NftId nftId = _registry.getNftId(address(this));
|
42
|
+
return nftId.gtz();
|
43
|
+
}
|
44
|
+
|
45
|
+
function getNftId() public view override returns (NftId nftId) {
|
46
|
+
return _registry.getNftId(address(this));
|
47
|
+
}
|
48
|
+
|
49
|
+
function getOwner() public view override returns (address owner) {
|
50
|
+
NftId id = _registry.getNftId(address(this));
|
51
|
+
owner = _registry.getOwner(id);
|
52
|
+
return owner != address(0) ? owner : _initialOwner;
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
contract Registry is IRegistry {
|
57
|
+
using NftIdLib for NftId;
|
58
|
+
|
59
|
+
string public constant EMPTY_URI = "";
|
60
|
+
|
61
|
+
mapping(NftId nftId => RegistryInfo info) private _info;
|
62
|
+
mapping(NftId nftId => address owner) private _owner;
|
63
|
+
mapping(address object => NftId nftId) private _nftIdByAddress;
|
64
|
+
|
65
|
+
IChainNft private _chainNft;
|
66
|
+
|
67
|
+
function initialize(address chainNft) external {
|
68
|
+
require(
|
69
|
+
address(_chainNft) == address(0),
|
70
|
+
"ERROR:REG-001:ALREADY_INITIALIZED"
|
71
|
+
);
|
72
|
+
_chainNft = IChainNft(chainNft);
|
73
|
+
}
|
74
|
+
|
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
|
+
);
|
82
|
+
|
83
|
+
IRegisterable registerable = IRegisterable(objectAddress);
|
84
|
+
require(
|
85
|
+
registerable.isRegisterable(),
|
86
|
+
"ERROR:REG-003:NOT_REGISTERABLE"
|
87
|
+
);
|
88
|
+
|
89
|
+
// check parent exists (for objects not instances)
|
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");
|
95
|
+
// check validity of parent relation, valid relations are
|
96
|
+
// policy -> product, bundle -> pool, product -> instance, pool -> instance
|
97
|
+
}
|
98
|
+
|
99
|
+
uint256 mintedTokenId = _chainNft.mint(
|
100
|
+
registerable.getInitialOwner(),
|
101
|
+
EMPTY_URI
|
102
|
+
);
|
103
|
+
nftId = toNftId(mintedTokenId);
|
104
|
+
|
105
|
+
RegistryInfo memory info = RegistryInfo(
|
106
|
+
nftId,
|
107
|
+
registerable.getParentNftId(),
|
108
|
+
registerable.getType(),
|
109
|
+
objectAddress,
|
110
|
+
registerable.getInitialOwner()
|
111
|
+
);
|
112
|
+
|
113
|
+
_info[nftId] = info;
|
114
|
+
_nftIdByAddress[objectAddress] = nftId;
|
115
|
+
|
116
|
+
// add logging
|
117
|
+
}
|
118
|
+
|
119
|
+
function registerObjectForInstance(
|
120
|
+
NftId parentNftId,
|
121
|
+
ObjectType objectType,
|
122
|
+
address initialOwner
|
123
|
+
)
|
124
|
+
external
|
125
|
+
override
|
126
|
+
returns (
|
127
|
+
// TODO add onlyRegisteredInstance
|
128
|
+
NftId nftId
|
129
|
+
)
|
130
|
+
{
|
131
|
+
// TODO add more validation
|
132
|
+
require(
|
133
|
+
objectType == POLICY() || objectType == BUNDLE(),
|
134
|
+
"ERROR:REG-005:TYPE_INVALID"
|
135
|
+
);
|
136
|
+
|
137
|
+
uint256 mintedTokenId = _chainNft.mint(initialOwner, EMPTY_URI);
|
138
|
+
nftId = toNftId(mintedTokenId);
|
139
|
+
|
140
|
+
RegistryInfo memory info = RegistryInfo(
|
141
|
+
nftId,
|
142
|
+
parentNftId,
|
143
|
+
objectType,
|
144
|
+
address(0),
|
145
|
+
initialOwner
|
146
|
+
);
|
147
|
+
|
148
|
+
_info[nftId] = info;
|
149
|
+
|
150
|
+
// add logging
|
151
|
+
}
|
152
|
+
|
153
|
+
function getObjectCount() external view override returns (uint256) {
|
154
|
+
return _chainNft.totalSupply();
|
155
|
+
}
|
156
|
+
|
157
|
+
function getNftId(
|
158
|
+
address object
|
159
|
+
) external view override returns (NftId id) {
|
160
|
+
return _nftIdByAddress[object];
|
161
|
+
}
|
162
|
+
|
163
|
+
function isRegistered(
|
164
|
+
address object
|
165
|
+
) external view override returns (bool) {
|
166
|
+
return _nftIdByAddress[object].gtz();
|
167
|
+
}
|
168
|
+
|
169
|
+
function getInfo(
|
170
|
+
NftId nftId
|
171
|
+
) external view override returns (RegistryInfo memory info) {
|
172
|
+
return _info[nftId];
|
173
|
+
}
|
174
|
+
|
175
|
+
function getOwner(NftId nftId) external view override returns (address) {
|
176
|
+
return _chainNft.ownerOf(nftId.toInt());
|
177
|
+
}
|
178
|
+
|
179
|
+
function getNftAddress() external view override returns (address nft) {
|
180
|
+
return address(_chainNft);
|
181
|
+
}
|
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
|
+
}
|