@etherisc/gif-next 0.0.2-836a512-798 → 0.0.2-839b2a2-792
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 +8 -0
- package/artifacts/contracts/components/Component.sol/Component.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/Component.json +1 -1
- package/artifacts/contracts/components/Component.sol/InstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/components/Component.sol/InstanceLinked.json +2 -2
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.dbg.json +1 -1
- package/artifacts/contracts/components/IPool.sol/IPoolComponent.json +1 -1
- package/artifacts/contracts/components/IProduct.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 +5 -5
- package/artifacts/contracts/components/Product.sol/Product.dbg.json +1 -1
- package/artifacts/contracts/components/Product.sol/Product.json +5 -5
- package/artifacts/contracts/experiment/errors/Require.sol/Require.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Require.sol/Require.json +2 -2
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.dbg.json +1 -1
- package/artifacts/contracts/experiment/errors/Revert.sol/Revert.json +2 -2
- package/artifacts/contracts/experiment/inheritance/A.sol/A.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/A.json +2 -2
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/A.sol/AShared.json +2 -2
- package/artifacts/contracts/experiment/inheritance/B.sol/B.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/C.sol/C.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/IA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IA.sol/ISharedA.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IB.sol/IB.dbg.json +1 -1
- package/artifacts/contracts/experiment/inheritance/IC.sol/IC.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/Dummy.sol/LifeCycleModule.json +2 -2
- 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/SM.sol/SM.json +2 -2
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.dbg.json +1 -1
- package/artifacts/contracts/experiment/statemachine/SimpleStateMachine.sol/SimpleStateMachine.json +2 -2
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeA.sol/TypeALib.json +2 -2
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.dbg.json +1 -1
- package/artifacts/contracts/experiment/types/TypeB.sol/TypeBLib.json +2 -2
- package/artifacts/contracts/instance/IInstance.sol/IInstance.dbg.json +1 -1
- package/artifacts/contracts/instance/IInstance.sol/IInstance.json +137 -21
- package/artifacts/contracts/instance/Instance.sol/Instance.dbg.json +1 -1
- package/artifacts/contracts/instance/Instance.sol/Instance.json +175 -35
- package/artifacts/contracts/instance/access/Access.sol/AccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccess.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessCheckRole.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessComponentTypeRoles.dbg.json +1 -1
- package/artifacts/contracts/instance/access/IAccess.sol/IAccessModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentModule.json +2 -21
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/ComponentModule.sol/ComponentOwnerService.json +65 -10
- package/artifacts/contracts/instance/component/IComponent.sol/IComponent.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentContract.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentModule.json +2 -21
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.dbg.json +1 -1
- package/artifacts/contracts/instance/component/IComponent.sol/IComponentOwnerService.json +47 -0
- package/artifacts/contracts/instance/component/IComponent.sol/IInstanceLinked.dbg.json +1 -1
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycle.dbg.json +1 -1
- package/artifacts/contracts/instance/lifecycle/ILifecycle.sol/ILifecycleModule.dbg.json +1 -1
- package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.dbg.json +1 -1
- package/artifacts/contracts/instance/lifecycle/LifecycleModule.sol/LifecycleModule.json +2 -2
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicy.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/IPolicy.sol/IPolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/policy/PolicyModule.sol/PolicyModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPool.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/IPoolModule.sol/IPoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/pool/PoolModule.sol/PoolModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/IProductService.sol/IProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductModule.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.dbg.json +1 -1
- package/artifacts/contracts/instance/product/ProductService.sol/ProductService.json +14 -14
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasury.dbg.json +1 -1
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.dbg.json +1 -1
- package/artifacts/contracts/instance/treasury/ITreasury.sol/ITreasuryModule.json +135 -0
- package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.dbg.json +1 -1
- package/artifacts/contracts/instance/treasury/TokenHandler.sol/TokenHandler.json +2 -2
- package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.dbg.json +1 -1
- package/artifacts/contracts/instance/treasury/TreasuryModule.sol/TreasuryModule.json +135 -0
- package/artifacts/contracts/mock/Dip.sol/DIP.dbg.json +4 -0
- package/artifacts/contracts/mock/Dip.sol/DIP.json +338 -0
- package/artifacts/contracts/mock/TestPool.sol/TestPool.dbg.json +4 -0
- package/artifacts/contracts/mock/TestPool.sol/TestPool.json +294 -0
- package/artifacts/contracts/mock/TestProduct.sol/TestProduct.dbg.json +4 -0
- package/artifacts/contracts/mock/TestProduct.sol/TestProduct.json +384 -0
- package/artifacts/contracts/mock/Usdc.sol/USDC.dbg.json +4 -0
- package/artifacts/contracts/mock/Usdc.sol/USDC.json +338 -0
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/ChainNft.sol/ChainNft.json +2 -2
- package/artifacts/contracts/registry/IChainNft.sol/IChainNft.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IOwnable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegisterable.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistry.dbg.json +1 -1
- package/artifacts/contracts/registry/IRegistry.sol/IRegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registerable.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/Registry.json +10 -10
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.dbg.json +1 -1
- package/artifacts/contracts/registry/Registry.sol/RegistryLinked.json +2 -2
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.dbg.json +1 -1
- package/artifacts/contracts/types/Blocknumber.sol/BlocknumberLib.json +2 -2
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/ChainId.sol/ChainIdLib.json +2 -2
- package/artifacts/contracts/types/NftId.sol/NftIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/NftId.sol/NftIdLib.json +2 -2
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.dbg.json +1 -1
- package/artifacts/contracts/types/ObjectType.sol/ObjectTypeLib.json +2 -2
- package/artifacts/contracts/types/StateId.sol/StateIdLib.dbg.json +1 -1
- package/artifacts/contracts/types/StateId.sol/StateIdLib.json +2 -2
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.dbg.json +1 -1
- package/artifacts/contracts/types/Timestamp.sol/TimestampLib.json +2 -2
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.dbg.json +1 -1
- package/artifacts/contracts/types/UFixed.sol/UFixedMathLib.json +37 -11
- package/contracts/components/Component.sol +12 -12
- package/contracts/components/IPool.sol +6 -2
- package/contracts/components/IProduct.sol +7 -2
- package/contracts/components/Pool.sol +14 -7
- package/contracts/components/Product.sol +14 -6
- package/contracts/experiment/statemachine/Dummy.sol +12 -18
- package/contracts/experiment/statemachine/ISM.sol +7 -2
- package/contracts/experiment/statemachine/SM.sol +15 -12
- package/contracts/experiment/statemachine/SimpleStateMachine.sol +11 -4
- package/contracts/instance/IInstance.sol +4 -1
- package/contracts/instance/Instance.sol +8 -5
- package/contracts/instance/component/ComponentModule.sol +55 -35
- package/contracts/instance/component/IComponent.sol +12 -14
- package/contracts/instance/lifecycle/ILifecycle.sol +32 -17
- package/contracts/instance/lifecycle/LifecycleModule.sol +28 -31
- package/contracts/instance/policy/IPolicy.sol +0 -2
- package/contracts/instance/policy/PolicyModule.sol +14 -7
- package/contracts/instance/pool/IPoolModule.sol +3 -2
- package/contracts/instance/pool/PoolModule.sol +11 -12
- package/contracts/instance/product/ProductService.sol +30 -12
- package/contracts/instance/treasury/ITreasury.sol +43 -25
- package/contracts/instance/treasury/TokenHandler.sol +1 -4
- package/contracts/instance/treasury/TreasuryModule.sol +82 -45
- package/contracts/mock/Dip.sol +26 -0
- package/contracts/mock/TestPool.sol +16 -0
- package/contracts/mock/TestProduct.sol +39 -0
- package/contracts/mock/Usdc.sol +26 -0
- package/contracts/registry/IRegistry.sol +0 -2
- package/contracts/registry/Registry.sol +7 -2
- package/contracts/types/Fee.sol +6 -4
- package/contracts/types/ObjectType.sol +77 -20
- package/contracts/types/StateId.sol +68 -23
- package/contracts/types/UFixed.sol +18 -14
- package/package.json +4 -2
@@ -0,0 +1,39 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.19;
|
3
|
+
|
4
|
+
import {Product} from "../../contracts/components/Product.sol";
|
5
|
+
import {NftId, toNftId} from "../../contracts/types/NftId.sol";
|
6
|
+
import {Fee, zeroFee} from "../../contracts/types/Fee.sol";
|
7
|
+
|
8
|
+
contract TestProduct is Product {
|
9
|
+
|
10
|
+
constructor(address registry, address instance, address token, address pool, Fee memory policyFee)
|
11
|
+
Product(registry, instance, token, pool, policyFee, zeroFee())
|
12
|
+
// solhint-disable-next-line no-empty-blocks
|
13
|
+
{}
|
14
|
+
|
15
|
+
function applyForPolicy(
|
16
|
+
uint256 sumInsuredAmount,
|
17
|
+
uint256 premiumAmount,
|
18
|
+
uint256 lifetime
|
19
|
+
)
|
20
|
+
external
|
21
|
+
returns(NftId nftId)
|
22
|
+
{
|
23
|
+
nftId = _createApplication(
|
24
|
+
msg.sender, // policy holder
|
25
|
+
sumInsuredAmount,
|
26
|
+
premiumAmount,
|
27
|
+
lifetime,
|
28
|
+
toNftId(0) // requested bundle nft id
|
29
|
+
);
|
30
|
+
}
|
31
|
+
|
32
|
+
function underwrite(NftId nftId) external {
|
33
|
+
_underwrite(nftId);
|
34
|
+
}
|
35
|
+
|
36
|
+
function collectPremium(NftId nftId) external {
|
37
|
+
_collectPremium(nftId);
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
2
|
+
pragma solidity ^0.8.20;
|
3
|
+
|
4
|
+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
5
|
+
|
6
|
+
contract USDC is ERC20 {
|
7
|
+
|
8
|
+
// https://etherscan.io/token/0xc719d010b63e5bbf2c0551872cd5316ed26acd83#readContract
|
9
|
+
string public constant NAME = "USDC - DUMMY";
|
10
|
+
string public constant SYMBOL = "USDC";
|
11
|
+
uint8 public constant DECIMALS = 6;
|
12
|
+
uint256 public constant INITIAL_SUPPLY = 10**9 * 10**DECIMALS; // 1 Billion 1'000'000'000
|
13
|
+
// decimals == 18 (openzeppelin erc20 default)
|
14
|
+
constructor()
|
15
|
+
ERC20(NAME, SYMBOL)
|
16
|
+
{
|
17
|
+
_mint(
|
18
|
+
_msgSender(),
|
19
|
+
INITIAL_SUPPLY
|
20
|
+
);
|
21
|
+
}
|
22
|
+
|
23
|
+
function decimals() public pure override returns(uint8) {
|
24
|
+
return DECIMALS;
|
25
|
+
}
|
26
|
+
}
|
@@ -15,7 +15,6 @@ interface IRegistryLinked {
|
|
15
15
|
}
|
16
16
|
|
17
17
|
interface IRegisterable is IOwnable, IRegistryLinked {
|
18
|
-
|
19
18
|
function register() external returns (NftId nftId);
|
20
19
|
|
21
20
|
function getNftId() external view returns (NftId nftId);
|
@@ -34,7 +33,6 @@ interface IRegisterable is IOwnable, IRegistryLinked {
|
|
34
33
|
}
|
35
34
|
|
36
35
|
interface IRegistry {
|
37
|
-
|
38
36
|
struct RegistryInfo {
|
39
37
|
NftId nftId;
|
40
38
|
NftId parentNftId;
|
@@ -72,8 +72,13 @@ contract Registry is IRegistry {
|
|
72
72
|
_chainNft = IChainNft(chainNft);
|
73
73
|
}
|
74
74
|
|
75
|
-
function register(
|
76
|
-
|
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
|
+
);
|
77
82
|
|
78
83
|
IRegisterable registerable = IRegisterable(objectAddress);
|
79
84
|
require(
|
package/contracts/types/Fee.sol
CHANGED
@@ -10,7 +10,10 @@ struct Fee {
|
|
10
10
|
|
11
11
|
// general pure free functions
|
12
12
|
/// @dev Converts the uint256 to a NftId.
|
13
|
-
function toFee(
|
13
|
+
function toFee(
|
14
|
+
UFixed fractionalFee,
|
15
|
+
uint256 fixedFee
|
16
|
+
) pure returns (Fee memory fee) {
|
14
17
|
return Fee(fractionalFee, fixedFee);
|
15
18
|
}
|
16
19
|
|
@@ -24,7 +27,6 @@ function feeIsSame(Fee memory a, Fee memory b) pure returns (bool isSame) {
|
|
24
27
|
return a.fixedFee == b.fixedFee && a.fractionalFee == b.fractionalFee;
|
25
28
|
}
|
26
29
|
|
27
|
-
|
28
|
-
function feeIsZero(Fee memory fee) pure returns(bool) {
|
30
|
+
function feeIsZero(Fee memory fee) pure returns (bool) {
|
29
31
|
return fee.fixedFee == 0 && UFixed.unwrap(fee.fractionalFee) == 0;
|
30
|
-
}
|
32
|
+
}
|
@@ -13,38 +13,95 @@ using {
|
|
13
13
|
|
14
14
|
// general pure free functions
|
15
15
|
|
16
|
+
function PROTOCOL() pure returns (ObjectType) {
|
17
|
+
return toObjectType(10);
|
18
|
+
}
|
19
|
+
|
20
|
+
function CHAIN() pure returns (ObjectType) {
|
21
|
+
return toObjectType(20);
|
22
|
+
}
|
23
|
+
|
24
|
+
function REGISTRY() pure returns (ObjectType) {
|
25
|
+
return toObjectType(30);
|
26
|
+
}
|
27
|
+
|
28
|
+
function TOKEN() pure returns (ObjectType) {
|
29
|
+
return toObjectType(40);
|
30
|
+
}
|
31
|
+
|
32
|
+
function INSTANCE() pure returns (ObjectType) {
|
33
|
+
return toObjectType(50);
|
34
|
+
}
|
35
|
+
|
36
|
+
function PRODUCT() pure returns (ObjectType) {
|
37
|
+
return toObjectType(60);
|
38
|
+
}
|
39
|
+
|
40
|
+
function ORACLE() pure returns (ObjectType) {
|
41
|
+
return toObjectType(70);
|
42
|
+
}
|
43
|
+
|
44
|
+
function POOL() pure returns (ObjectType) {
|
45
|
+
return toObjectType(80);
|
46
|
+
}
|
16
47
|
|
17
|
-
function
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
function
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
function
|
26
|
-
|
27
|
-
|
28
|
-
|
48
|
+
function BUNDLE() pure returns (ObjectType) {
|
49
|
+
return toObjectType(81);
|
50
|
+
}
|
51
|
+
|
52
|
+
function POLICY() pure returns (ObjectType) {
|
53
|
+
return toObjectType(90);
|
54
|
+
}
|
55
|
+
|
56
|
+
function CLAIM() pure returns (ObjectType) {
|
57
|
+
return toObjectType(91);
|
58
|
+
}
|
59
|
+
|
60
|
+
function PAYOUT() pure returns (ObjectType) {
|
61
|
+
return toObjectType(92);
|
62
|
+
}
|
29
63
|
|
30
64
|
/// @dev Converts the uint8 to a ObjectType.
|
31
|
-
function toObjectType(uint256 objectType) pure returns(ObjectType) {
|
65
|
+
function toObjectType(uint256 objectType) pure returns (ObjectType) {
|
66
|
+
return ObjectType.wrap(uint8(objectType));
|
67
|
+
}
|
32
68
|
|
33
69
|
/// @dev Return the ObjectType zero (0)
|
34
|
-
function zeroObjectType() pure returns(ObjectType) {
|
70
|
+
function zeroObjectType() pure returns (ObjectType) {
|
71
|
+
return ObjectType.wrap(0);
|
72
|
+
}
|
35
73
|
|
36
74
|
// pure free functions for operators
|
37
|
-
function eqObjectType(ObjectType a, ObjectType b) pure returns(bool isSame) {
|
38
|
-
|
75
|
+
function eqObjectType(ObjectType a, ObjectType b) pure returns (bool isSame) {
|
76
|
+
return ObjectType.unwrap(a) == ObjectType.unwrap(b);
|
77
|
+
}
|
78
|
+
|
79
|
+
function neObjectType(
|
80
|
+
ObjectType a,
|
81
|
+
ObjectType b
|
82
|
+
) pure returns (bool isDifferent) {
|
83
|
+
return ObjectType.unwrap(a) != ObjectType.unwrap(b);
|
84
|
+
}
|
39
85
|
|
40
86
|
// library functions that operate on user defined type
|
41
87
|
library ObjectTypeLib {
|
42
88
|
/// @dev Converts the NftId to a uint256.
|
43
|
-
function toInt(ObjectType objectType) public pure returns(uint96) {
|
89
|
+
function toInt(ObjectType objectType) public pure returns (uint96) {
|
90
|
+
return uint96(ObjectType.unwrap(objectType));
|
91
|
+
}
|
92
|
+
|
44
93
|
/// @dev Returns true if the value is non-zero (> 0).
|
45
|
-
function gtz(ObjectType a) public pure returns(bool) {
|
94
|
+
function gtz(ObjectType a) public pure returns (bool) {
|
95
|
+
return ObjectType.unwrap(a) > 0;
|
96
|
+
}
|
97
|
+
|
46
98
|
/// @dev Returns true if the value is zero (== 0).
|
47
|
-
function eqz(ObjectType a) public pure returns(bool) {
|
99
|
+
function eqz(ObjectType a) public pure returns (bool) {
|
100
|
+
return ObjectType.unwrap(a) == 0;
|
101
|
+
}
|
102
|
+
|
48
103
|
/// @dev Returns true if the values are equal (==).
|
49
|
-
function eq(ObjectType a, ObjectType b) public pure returns(bool isSame) {
|
104
|
+
function eq(ObjectType a, ObjectType b) public pure returns (bool isSame) {
|
105
|
+
return eqObjectType(a, b);
|
106
|
+
}
|
50
107
|
}
|
@@ -5,42 +5,87 @@ pragma solidity ^0.8.19;
|
|
5
5
|
type StateId is uint8;
|
6
6
|
|
7
7
|
// type bindings
|
8
|
-
using {
|
9
|
-
eqStateId as ==,
|
10
|
-
neStateId as !=,
|
11
|
-
StateIdLib.toInt
|
12
|
-
} for StateId global;
|
8
|
+
using {eqStateId as ==, neStateId as !=, StateIdLib.toInt} for StateId global;
|
13
9
|
|
14
10
|
// general pure free functions
|
15
|
-
function APPLIED() pure returns(StateId) {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
function
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
function
|
24
|
-
|
11
|
+
function APPLIED() pure returns (StateId) {
|
12
|
+
return toStateId(10);
|
13
|
+
}
|
14
|
+
|
15
|
+
function REVOKED() pure returns (StateId) {
|
16
|
+
return toStateId(20);
|
17
|
+
}
|
18
|
+
|
19
|
+
function DECLINED() pure returns (StateId) {
|
20
|
+
return toStateId(30);
|
21
|
+
}
|
22
|
+
|
23
|
+
function CONFIRMED() pure returns (StateId) {
|
24
|
+
return toStateId(40);
|
25
|
+
}
|
26
|
+
|
27
|
+
function EXPECTED() pure returns (StateId) {
|
28
|
+
return toStateId(50);
|
29
|
+
}
|
30
|
+
|
31
|
+
function ACTIVE() pure returns (StateId) {
|
32
|
+
return toStateId(100);
|
33
|
+
}
|
34
|
+
|
35
|
+
function PAUSED() pure returns (StateId) {
|
36
|
+
return toStateId(110);
|
37
|
+
}
|
38
|
+
|
39
|
+
function CLOSED() pure returns (StateId) {
|
40
|
+
return toStateId(200);
|
41
|
+
}
|
42
|
+
|
43
|
+
function ARCHIVED() pure returns (StateId) {
|
44
|
+
return toStateId(210);
|
45
|
+
}
|
46
|
+
|
47
|
+
function PAID() pure returns (StateId) {
|
48
|
+
return toStateId(220);
|
49
|
+
}
|
25
50
|
|
26
51
|
/// @dev Converts the uint8 to a StateId.
|
27
|
-
function toStateId(uint256 id) pure returns(StateId) {
|
52
|
+
function toStateId(uint256 id) pure returns (StateId) {
|
53
|
+
return StateId.wrap(uint8(id));
|
54
|
+
}
|
28
55
|
|
29
56
|
/// @dev Return the StateId zero (0)
|
30
|
-
function zeroStateId() pure returns(StateId) {
|
57
|
+
function zeroStateId() pure returns (StateId) {
|
58
|
+
return StateId.wrap(0);
|
59
|
+
}
|
31
60
|
|
32
61
|
// pure free functions for operators
|
33
|
-
function eqStateId(StateId a, StateId b) pure returns(bool isSame) {
|
34
|
-
|
62
|
+
function eqStateId(StateId a, StateId b) pure returns (bool isSame) {
|
63
|
+
return StateId.unwrap(a) == StateId.unwrap(b);
|
64
|
+
}
|
65
|
+
|
66
|
+
function neStateId(StateId a, StateId b) pure returns (bool isDifferent) {
|
67
|
+
return StateId.unwrap(a) != StateId.unwrap(b);
|
68
|
+
}
|
35
69
|
|
36
70
|
// library functions that operate on user defined type
|
37
71
|
library StateIdLib {
|
38
72
|
/// @dev Converts the NftId to a uint256.
|
39
|
-
function toInt(StateId stateId) public pure returns(uint96) {
|
73
|
+
function toInt(StateId stateId) public pure returns (uint96) {
|
74
|
+
return uint96(StateId.unwrap(stateId));
|
75
|
+
}
|
76
|
+
|
40
77
|
/// @dev Returns true if the value is non-zero (> 0).
|
41
|
-
function gtz(StateId a) public pure returns(bool) {
|
78
|
+
function gtz(StateId a) public pure returns (bool) {
|
79
|
+
return StateId.unwrap(a) > 0;
|
80
|
+
}
|
81
|
+
|
42
82
|
/// @dev Returns true if the value is zero (== 0).
|
43
|
-
function eqz(StateId a) public pure returns(bool) {
|
83
|
+
function eqz(StateId a) public pure returns (bool) {
|
84
|
+
return StateId.unwrap(a) == 0;
|
85
|
+
}
|
86
|
+
|
44
87
|
/// @dev Returns true if the values are equal (==).
|
45
|
-
function eq(StateId a, StateId b) public pure returns(bool isSame) {
|
88
|
+
function eq(StateId a, StateId b) public pure returns (bool isSame) {
|
89
|
+
return eqStateId(a, b);
|
90
|
+
}
|
46
91
|
}
|
@@ -76,21 +76,25 @@ function deltaUFixed(UFixed a, UFixed b) pure returns (UFixed) {
|
|
76
76
|
}
|
77
77
|
|
78
78
|
library UFixedMathLib {
|
79
|
-
enum Rounding {
|
80
|
-
/// @dev Round down - floor(value)
|
81
|
-
Down,
|
82
|
-
/// @dev Round up - ceil(value)
|
83
|
-
Up,
|
84
|
-
/// @dev Round half up - round(value)
|
85
|
-
HalfUp
|
86
|
-
}
|
87
79
|
|
88
80
|
int8 public constant EXP = 18;
|
89
81
|
uint256 public constant MULTIPLIER = 10 ** uint256(int256(EXP));
|
90
82
|
uint256 public constant MULTIPLIER_HALF = MULTIPLIER / 2;
|
91
83
|
|
92
|
-
/// @dev
|
93
|
-
|
84
|
+
/// @dev returns the rounding mode DOWN - 0.4 becomes 0, 0.5 becomes 0, 0.6 becomes 0
|
85
|
+
function ROUNDING_DOWN() public pure returns (uint8) {
|
86
|
+
return uint8(0);
|
87
|
+
}
|
88
|
+
|
89
|
+
/// @dev returns the rounding mode UP - 0.4 becomes 1, 0.5 becomes 1, 0.6 becomes 1
|
90
|
+
function ROUNDING_UP() public pure returns (uint8) {
|
91
|
+
return uint8(1);
|
92
|
+
}
|
93
|
+
|
94
|
+
/// @dev returns the rounding mode HALF_UP - 0.4 becomes 0, 0.5 becomes 1, 0.6 becomes 1
|
95
|
+
function ROUNDING_HALF_UP() public pure returns (uint8) {
|
96
|
+
return uint8(2);
|
97
|
+
}
|
94
98
|
|
95
99
|
/// @dev returns the decimals precision of the UFixed type
|
96
100
|
function decimals() public pure returns (uint256) {
|
@@ -113,12 +117,12 @@ library UFixedMathLib {
|
|
113
117
|
|
114
118
|
/// @dev Converts a UFixed to a uint256.
|
115
119
|
function ftoi(UFixed a) public pure returns (uint256) {
|
116
|
-
return ftoi(a,
|
120
|
+
return ftoi(a, ROUNDING_HALF_UP());
|
117
121
|
}
|
118
122
|
|
119
123
|
/// @dev Converts a UFixed to a uint256 with given rounding mode.
|
120
|
-
function ftoi(UFixed a,
|
121
|
-
if (rounding ==
|
124
|
+
function ftoi(UFixed a, uint8 rounding) public pure returns (uint256) {
|
125
|
+
if (rounding == ROUNDING_HALF_UP()) {
|
122
126
|
return
|
123
127
|
Math.mulDiv(
|
124
128
|
UFixed.unwrap(a) + MULTIPLIER_HALF,
|
@@ -126,7 +130,7 @@ library UFixedMathLib {
|
|
126
130
|
MULTIPLIER,
|
127
131
|
Math.Rounding.Down
|
128
132
|
);
|
129
|
-
} else if (rounding ==
|
133
|
+
} else if (rounding == ROUNDING_DOWN()) {
|
130
134
|
return
|
131
135
|
Math.mulDiv(
|
132
136
|
UFixed.unwrap(a),
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@etherisc/gif-next",
|
3
|
-
"version": "0.0.2-
|
3
|
+
"version": "0.0.2-839b2a2-792",
|
4
4
|
"description": "This is the repository for the next version of the Generic Insurance Framework (GIF) smart contracts. ",
|
5
5
|
"main": "index.js",
|
6
6
|
"scripts": {
|
@@ -38,6 +38,8 @@
|
|
38
38
|
},
|
39
39
|
"dependencies": {
|
40
40
|
"@openzeppelin/contracts": "^4.9.3",
|
41
|
-
"@openzeppelin/contracts-upgradeable": "^4.9.3"
|
41
|
+
"@openzeppelin/contracts-upgradeable": "^4.9.3",
|
42
|
+
"ethers": "^6.7.1",
|
43
|
+
"winston": "^3.10.0"
|
42
44
|
}
|
43
45
|
}
|