diff --git a/README.md b/README.md index 71a2ffca6..4c099be8b 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,14 @@ hh run scripts/find_missing_virtual_methods.ts.ts Checks all public/external methods in services and components for methods that are not marked as `virtual` but should be. +### find upgradeable contracts storage locations + +```bash +grep -o -h -E '([A-Z0-9_]+_LOCATION_V[0-9]+_[0-9]+\s*=\s*0x[A-Ha-h0-9]+)' -r contracts +``` + +Prints addresses for each storage struct of each release of each upgradeable contract + ## Forge ### Commands diff --git a/contracts/distribution/Distribution.sol b/contracts/distribution/Distribution.sol index 348033cac..e57e261a1 100644 --- a/contracts/distribution/Distribution.sol +++ b/contracts/distribution/Distribution.sol @@ -22,8 +22,8 @@ abstract contract Distribution is InstanceLinkedComponent, IDistributionComponent { - // keccak256(abi.encode(uint256(keccak256("etherisc.storage.Distribution")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant DISTRIBUTION_STORAGE_LOCATION_V1 = 0xaab7c5ea03d290056d6c060e0833d3ebcbe647f7694616a2ec52738a64b2f900; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.Distribution@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant DISTRIBUTION_STORAGE_LOCATION_V3_0 = 0xf05be9ae88f1a13816beae3bf4177e164907f5d055d6c38ea0a1fabc08c6c500; struct DistributionStorage { IComponentService _componentService; @@ -241,7 +241,7 @@ abstract contract Distribution is function _getDistributionStorage() private pure returns (DistributionStorage storage $) { assembly { - $.slot := DISTRIBUTION_STORAGE_LOCATION_V1 + $.slot := DISTRIBUTION_STORAGE_LOCATION_V3_0 } } } diff --git a/contracts/oracle/Oracle.sol b/contracts/oracle/Oracle.sol index 065dda0d3..29c30f1b9 100644 --- a/contracts/oracle/Oracle.sol +++ b/contracts/oracle/Oracle.sol @@ -18,8 +18,8 @@ abstract contract Oracle is InstanceLinkedComponent, IOracleComponent { - // keccak256(abi.encode(uint256(keccak256("etherisc.storage.Oracle")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant ORACLE_STORAGE_LOCATION_V1 = 0xaab7c0ea03d290e56d6c060e0733d3ebcbe647f7694616a2ec52738a64b2f900; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.Oracle@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant ORACLE_STORAGE_LOCATION_V3_0 = 0x189f66bb26b02fde8f3e50c7c928f45e0131f04edebf4d58daf0aee756df0e00; struct OracleStorage { IComponentService _componentService; @@ -148,7 +148,7 @@ abstract contract Oracle is function _getOracleStorage() private pure returns (OracleStorage storage $) { assembly { - $.slot := ORACLE_STORAGE_LOCATION_V1 + $.slot := ORACLE_STORAGE_LOCATION_V3_0 } } } diff --git a/contracts/pool/BundleService.sol b/contracts/pool/BundleService.sol index eebdef81a..6a6e924f2 100644 --- a/contracts/pool/BundleService.sol +++ b/contracts/pool/BundleService.sol @@ -30,10 +30,15 @@ contract BundleService is string public constant NAME = "BundleService"; - address private _registryAddress; - IRegistryService private _registryService; - IAccountingService private _accountingService; - IComponentService private _componentService; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.BundleService@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant BUNDLE_SERVICE_STORAGE_LOCATION_V3_0 = 0x46b8ce3500c11673bb6f380e5e46ed88536ecfaa352cb594644cb469c5a14d00; + + struct BundleServiceStorage { + address _registryAddress; + IRegistryService _registryService; + IAccountingService _accountingService; + IComponentService _componentService; + } function _initialize( address owner, @@ -50,9 +55,10 @@ contract BundleService is __Service_init(authority, registry, owner); - _registryService = IRegistryService(_getServiceAddress(REGISTRY())); - _accountingService = IAccountingService(_getServiceAddress(ACCOUNTING())); - _componentService = IComponentService(_getServiceAddress(COMPONENT())); + BundleServiceStorage storage $ = _getBundleServiceStorage(); + $._registryService = IRegistryService(_getServiceAddress(REGISTRY())); + $._accountingService = IAccountingService(_getServiceAddress(ACCOUNTING())); + $._componentService = IComponentService(_getServiceAddress(COMPONENT())); _registerInterface(type(IBundleService).interfaceId); } @@ -100,7 +106,8 @@ contract BundleService is (NftId poolNftId, IInstance instance) = PoolLib.getAndVerifyActivePool(getRegistry(), msg.sender); // register bundle with registry - bundleNftId = _registryService.registerBundle( + BundleServiceStorage storage $ = _getBundleServiceStorage(); + bundleNftId = $._registryService.registerBundle( IRegistry.ObjectInfo( NftIdLib.zero(), poolNftId, @@ -261,7 +268,8 @@ contract BundleService is Amount balanceAmountWithFees = instanceReader.getBalanceAmount(bundleNftId); feeAmount = instanceReader.getFeeAmount(bundleNftId); unstakedAmount = balanceAmountWithFees - feeAmount; - _accountingService.decreaseBundleBalance(instanceStore, bundleNftId, unstakedAmount, feeAmount); + BundleServiceStorage storage $ = _getBundleServiceStorage(); + $._accountingService.decreaseBundleBalance(instanceStore, bundleNftId, unstakedAmount, feeAmount); } emit LogBundleServiceBundleClosed(bundleNftId); @@ -291,7 +299,8 @@ contract BundleService is } // effects - _accountingService.increaseBundleBalance( + BundleServiceStorage storage $ = _getBundleServiceStorage(); + $._accountingService.increaseBundleBalance( instanceStore, bundleNftId, amount, @@ -334,7 +343,8 @@ contract BundleService is } // effects - _accountingService.decreaseBundleBalance( + BundleServiceStorage storage $ = _getBundleServiceStorage(); + $._accountingService.decreaseBundleBalance( instanceStore, bundleNftId, unstakedAmount, @@ -399,6 +409,11 @@ contract BundleService is emit LogBundleServiceCollateralReleased(bundleNftId, policyNftId, collateralAmount); } + function _getBundleServiceStorage() private pure returns (BundleServiceStorage storage $) { + assembly { + $.slot := BUNDLE_SERVICE_STORAGE_LOCATION_V3_0 + } + } function _getDomain() internal pure override returns(ObjectType) { return BUNDLE(); diff --git a/contracts/pool/Pool.sol b/contracts/pool/Pool.sol index 4074980c8..a07373c52 100644 --- a/contracts/pool/Pool.sol +++ b/contracts/pool/Pool.sol @@ -23,8 +23,8 @@ abstract contract Pool is InstanceLinkedComponent, IPoolComponent { - // keccak256(abi.encode(uint256(keccak256("etherisc.storage.Pool")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant POOL_STORAGE_LOCATION_V1 = 0x25e3e51823fbfffb988e0a2744bb93722d9f3e906c07cc0a9e77884c46c58300; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.Pool@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant POOL_STORAGE_LOCATION_V3_0 = 0xceba0dc57a322ad9ac8622c7bbee3a223850780710333daffeacd4b6d53d6e00; struct PoolStorage { IComponents.PoolInfo _poolInfo; @@ -337,7 +337,7 @@ abstract contract Pool is function _getPoolStorage() private pure returns (PoolStorage storage $) { assembly { - $.slot := POOL_STORAGE_LOCATION_V1 + $.slot := POOL_STORAGE_LOCATION_V3_0 } } } diff --git a/contracts/pool/PoolService.sol b/contracts/pool/PoolService.sol index c3c46a1a6..c87f218b4 100644 --- a/contracts/pool/PoolService.sol +++ b/contracts/pool/PoolService.sol @@ -31,10 +31,15 @@ contract PoolService is Service, IPoolService { - IAccountingService private _accountingService; - IBundleService internal _bundleService; - IComponentService internal _componentService; - IStaking private _staking; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.PoolService@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant POOL_SERVICE_STORAGE_LOCATION_V3_0 = 0x99b25f02200e1434f4531a215abb8fd8c59ad15f6abb6b06ffa8223eb7162700; + + struct PoolServiceStorage { + IAccountingService _accountingService; + IBundleService _bundleService; + IComponentService _componentService; + IStaking _staking; + } function _initialize( address owner, @@ -51,10 +56,11 @@ contract PoolService is __Service_init(authority, registry, owner); - _accountingService = IAccountingService(_getServiceAddress(ACCOUNTING())); - _bundleService = IBundleService(_getServiceAddress(BUNDLE())); - _componentService = IComponentService(_getServiceAddress(COMPONENT())); - _staking = IStaking(getRegistry().getStakingAddress()); + PoolServiceStorage storage $ = _getPoolServiceStorage(); + $._accountingService = IAccountingService(_getServiceAddress(ACCOUNTING())); + $._bundleService = IBundleService(_getServiceAddress(BUNDLE())); + $._componentService = IComponentService(_getServiceAddress(COMPONENT())); + $._staking = IStaking(getRegistry().getStakingAddress()); _registerInterface(type(IPoolService).interfaceId); } @@ -90,9 +96,10 @@ contract PoolService is // TODO get performance fee for pool (#477) // releasing collateral in bundle - (Amount unstakedAmount, Amount feeAmount) = _bundleService.close(instance, bundleNftId); + PoolServiceStorage storage $ = _getPoolServiceStorage(); + (Amount unstakedAmount, Amount feeAmount) = $._bundleService.close(instance, bundleNftId); - _accountingService.decreasePoolBalance( + $._accountingService.decreasePoolBalance( instance.getInstanceStore(), poolNftId, unstakedAmount + feeAmount, @@ -205,13 +212,14 @@ contract PoolService is amount); // do all the book keeping - _accountingService.increasePoolBalance( + PoolServiceStorage storage $ = _getPoolServiceStorage(); + $._accountingService.increasePoolBalance( instanceStore, poolNftId, netAmount, feeAmount); - _bundleService.stake(instanceReader, instanceStore, bundleNftId, netAmount); + $._bundleService.stake(instanceReader, instanceStore, bundleNftId, netAmount); emit LogPoolServiceBundleStaked(instanceNftId, poolNftId, bundleNftId, amount, netAmount); @@ -244,7 +252,8 @@ contract PoolService is ) = PoolLib.checkAndGetPoolInfo(getRegistry(), msg.sender, bundleNftId); // call bundle service for bookkeeping and additional checks - Amount unstakedAmount = _bundleService.unstake(instanceStore, bundleNftId, amount); + PoolServiceStorage storage $ = _getPoolServiceStorage(); + Amount unstakedAmount = $._bundleService.unstake(instanceStore, bundleNftId, amount); // Important: from now on work only with unstakedAmount as it is the only reliable amount. // if amount was max, this was set to the available amount @@ -252,8 +261,8 @@ contract PoolService is // TODO: handle performance fees (issue #477) netAmount = unstakedAmount; - // update pool bookkeeping - performance fees stay in the pool, but as fees - _accountingService.decreasePoolBalance( + // update pool bookkeeping - performance fees stay in the pool, but as fees + $._accountingService.decreasePoolBalance( instanceStore, poolNftId, unstakedAmount, @@ -350,13 +359,14 @@ contract PoolService is Amount bundleNetAmount = premium.netPremiumAmount; InstanceStore instanceStore = instance.getInstanceStore(); - _accountingService.increasePoolBalance( + PoolServiceStorage storage $ = _getPoolServiceStorage(); + $._accountingService.increasePoolBalance( instanceStore, poolNftId, bundleNetAmount + bundleFeeAmount, poolFeeAmount); - _accountingService.increaseBundleBalanceForPool( + $._accountingService.increaseBundleBalanceForPool( instanceStore, bundleNftId, bundleNetAmount, @@ -399,14 +409,15 @@ contract PoolService is sumInsuredAmount); // lock collateral amount from involved bundle - _bundleService.lockCollateral( + PoolServiceStorage storage $ = _getPoolServiceStorage(); + $._bundleService.lockCollateral( instance, applicationNftId, bundleNftId, localCollateralAmount); // update value locked with staking service - _staking.increaseTotalValueLocked( + $._staking.increaseTotalValueLocked( instance.getNftId(), token, totalCollateralAmount); @@ -455,20 +466,21 @@ contract PoolService is // effects NftId poolNftId = getRegistry().getParentNftId(bundleNftId); + PoolServiceStorage storage $ = _getPoolServiceStorage(); - _accountingService.decreasePoolBalance( + $._accountingService.decreasePoolBalance( instanceStore, poolNftId, payoutAmount, AmountLib.zero()); - _accountingService.decreaseBundleBalanceForPool( + $._accountingService.decreaseBundleBalanceForPool( instanceStore, bundleNftId, payoutAmount, AmountLib.zero()); - _bundleService.releaseCollateral( + $._bundleService.releaseCollateral( instanceStore, policyNftId, bundleNftId, @@ -477,7 +489,7 @@ contract PoolService is // update value locked with staking service TokenHandler poolTokenHandler = instanceReader.getTokenHandler(poolNftId); - _staking.decreaseTotalValueLocked( + $._staking.decreaseTotalValueLocked( instanceReader.getInstanceNftId(), address(poolTokenHandler.TOKEN()), payoutAmount); @@ -494,7 +506,7 @@ contract PoolService is payoutBeneficiary); if (processingFeeAmount.gtz()) { - _accountingService.increaseProductFeesForPool( + $._accountingService.increaseProductFeesForPool( instanceStore, productNftId, processingFeeAmount); @@ -541,10 +553,11 @@ contract PoolService is // decrease fee counters by withdrawnAmount { InstanceStore store = instance.getInstanceStore(); + PoolServiceStorage storage $ = _getPoolServiceStorage(); // decrease fee amount of the bundle - _accountingService.decreaseBundleBalanceForPool(store, bundleNftId, AmountLib.zero(), withdrawnAmount); + $._accountingService.decreaseBundleBalanceForPool(store, bundleNftId, AmountLib.zero(), withdrawnAmount); // decrease pool balance - _accountingService.decreasePoolBalance(store, poolNftId, withdrawnAmount, AmountLib.zero()); + $._accountingService.decreasePoolBalance(store, poolNftId, withdrawnAmount, AmountLib.zero()); } // interactions @@ -575,7 +588,9 @@ contract PoolService is Amount remainingCollateralAmount = policyInfo.sumInsuredAmount - policyInfo.claimAmount; - _bundleService.releaseCollateral( + // effects + PoolServiceStorage storage $ = _getPoolServiceStorage(); + $._bundleService.releaseCollateral( instance.getInstanceStore(), policyNftId, policyInfo.bundleNftId, @@ -583,7 +598,7 @@ contract PoolService is // update value locked with staking service InstanceReader instanceReader = instance.getInstanceReader(); - _staking.decreaseTotalValueLocked( + $._staking.decreaseTotalValueLocked( instanceReader.getInstanceNftId(), address(instanceReader.getToken(policyInfo.productNftId)), remainingCollateralAmount); @@ -607,6 +622,12 @@ contract PoolService is return PoolLib.getAndVerifyActivePool(getRegistry(), msg.sender); } + function _getPoolServiceStorage() private pure returns (PoolServiceStorage storage $) { + assembly { + $.slot := POOL_SERVICE_STORAGE_LOCATION_V3_0 + } + } + function _getDomain() internal pure override returns(ObjectType) { return POOL(); diff --git a/contracts/product/ApplicationService.sol b/contracts/product/ApplicationService.sol index 8879fa388..415f706c2 100644 --- a/contracts/product/ApplicationService.sol +++ b/contracts/product/ApplicationService.sol @@ -28,9 +28,14 @@ contract ApplicationService is Service, IApplicationService { - IDistributionService private _distributionService; - IPricingService private _pricingService; - IRegistryService private _registryService; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.ApplicationService@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant APPLICATION_SERVICE_STORAGE_LOCATION_V3_0 = 0x24398a4c04c22224171b7c40b992e9eaa2a85b3256e3f65fd9ba6cedb9459300; + + struct ApplicationServiceStorage { + IDistributionService _distributionService; + IPricingService _pricingService; + IRegistryService _registryService; + } function _initialize( address owner, @@ -47,9 +52,10 @@ contract ApplicationService is __Service_init(authority, registry, owner); - _distributionService = IDistributionService(_getServiceAddress(DISTRIBUTION())); - _pricingService = IPricingService(_getServiceAddress(PRICE())); - _registryService = IRegistryService(_getServiceAddress(REGISTRY())); + ApplicationServiceStorage storage $ = _getApplicationServiceStorage(); + $._distributionService = IDistributionService(_getServiceAddress(DISTRIBUTION())); + $._pricingService = IPricingService(_getServiceAddress(PRICE())); + $._registryService = IRegistryService(_getServiceAddress(REGISTRY())); _registerInterface(type(IApplicationService).interfaceId); } @@ -88,7 +94,8 @@ contract ApplicationService is // check referral with distribution { if (productInfo.hasDistribution && ! referralId.eqz()) { - if (!_distributionService.referralIsValid(productInfo.distributionNftId, referralId)) { + ApplicationServiceStorage storage $ = _getApplicationServiceStorage(); + if (!$._distributionService.referralIsValid(productInfo.distributionNftId, referralId)) { revert ErrorApplicationServiceReferralInvalid(productNftId, productInfo.distributionNftId, referralId); } } @@ -113,7 +120,8 @@ contract ApplicationService is applicationOwner, ""); - applicationNftId = _registryService.registerPolicy(objectInfo); + ApplicationServiceStorage storage $ = _getApplicationServiceStorage(); + applicationNftId = $._registryService.registerPolicy(objectInfo); } @@ -125,7 +133,9 @@ contract ApplicationService is view returns (Amount premiumAmount) { - return _pricingService.calculatePremium( + ApplicationServiceStorage storage $ = _getApplicationServiceStorage(); + + return $._pricingService.calculatePremium( info.productNftId, info.riskId, info.sumInsuredAmount, @@ -320,6 +330,12 @@ contract ApplicationService is instance = IInstance(instanceAddress); } + function _getApplicationServiceStorage() private pure returns (ApplicationServiceStorage storage $) { + // solhint-disable-next-line no-inline-assembly + assembly { + $.slot := APPLICATION_SERVICE_STORAGE_LOCATION_V3_0 + } + } function _getDomain() internal pure override returns(ObjectType) { return APPLICATION(); diff --git a/contracts/product/ClaimService.sol b/contracts/product/ClaimService.sol index 6d2f59f68..edf0d44ba 100644 --- a/contracts/product/ClaimService.sol +++ b/contracts/product/ClaimService.sol @@ -28,9 +28,13 @@ contract ClaimService is Service, IClaimService { + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.ClaimService@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant CLAIM_SERVICE_STORAGE_LOCATION_V3_0 = 0x4771e227a17c94c5fcc3dc9ac7f68c26e56ef575e6191f6a42c4520a600ee000; - IPolicyService internal _policyService; - IPoolService internal _poolService; + struct ClaimServiceStorage { + IPolicyService _policyService; + IPoolService _poolService; + } function _initialize( address owner, @@ -47,8 +51,9 @@ contract ClaimService is __Service_init(authority, registry, owner); - _policyService = IPolicyService(getRegistry().getServiceAddress(POLICY(), getVersion().toMajorPart())); - _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getVersion().toMajorPart())); + ClaimServiceStorage storage $ = _getClaimServiceStorage(); + $._policyService = IPolicyService(getRegistry().getServiceAddress(POLICY(), getVersion().toMajorPart())); + $._poolService = IPoolService(getRegistry().getServiceAddress(POOL(), getVersion().toMajorPart())); _registerInterface(type(IClaimService).interfaceId); } @@ -140,7 +145,8 @@ contract ClaimService is // should policy still be active it needs to become expired if (policyInfo.claimAmount >= policyInfo.sumInsuredAmount) { - _policyService.expirePolicy(instance, policyNftId, TimestampLib.blockTimestamp()); + ClaimServiceStorage storage $ = _getClaimServiceStorage(); + $._policyService.expirePolicy(instance, policyNftId, TimestampLib.blockTimestamp()); } emit LogClaimServiceClaimConfirmed(policyNftId, claimId, confirmedAmount); @@ -322,46 +328,46 @@ contract ClaimService is // checks ( ,, + // IInstance instance, InstanceReader instanceReader, InstanceStore instanceStore, IPolicy.PolicyInfo memory policyInfo ) = _verifyCallerWithPolicy(policyNftId); - IPolicy.ClaimInfo memory claimInfo; - address payoutBeneficiary; - Amount payoutAmount; - + // check that payout exists and is open { - // check that payout exists and is open - IPolicy.PayoutInfo memory payoutInfo = instanceReader.getPayoutInfo(policyNftId, payoutId); - payoutBeneficiary = payoutInfo.beneficiary; - payoutAmount = payoutInfo.amount; StateId payoutState = instanceReader.getPayoutState(policyNftId, payoutId); if(payoutState != EXPECTED()) { revert ErrorClaimServicePayoutNotExpected(policyNftId, payoutId, payoutState); } + } + + Amount payoutAmount; + address payoutBeneficiary; + + { + ClaimId claimId = payoutId.toClaimId(); + IPolicy.ClaimInfo memory claimInfo = instanceReader.getClaimInfo(policyNftId, claimId); + IPolicy.PayoutInfo memory payoutInfo = instanceReader.getPayoutInfo(policyNftId, payoutId); + + payoutAmount = payoutInfo.amount; + payoutBeneficiary = payoutInfo.beneficiary; // check that payout amount does not violate claim amount - claimInfo = instanceReader.getClaimInfo(policyNftId, payoutId.toClaimId()); - if(claimInfo.paidAmount + payoutInfo.amount > claimInfo.claimAmount) { + if(claimInfo.paidAmount + payoutAmount > claimInfo.claimAmount) { revert ErrorClaimServicePayoutExceedsClaimAmount( policyNftId, - payoutId.toClaimId(), + claimId, claimInfo.claimAmount, - claimInfo.paidAmount + payoutInfo.amount); + claimInfo.paidAmount + payoutAmount); } // effects // update and save payout info with instance payoutInfo.paidAt = TimestampLib.blockTimestamp(); instanceStore.updatePayout(policyNftId, payoutId, payoutInfo, PAID()); - } - // update and save claim info with instance - { - ClaimId claimId = payoutId.toClaimId(); - // TODO cleanup - // IPolicy.ClaimInfo memory claimInfo = instanceReader.getClaimInfo(policyNftId, claimId); + // update and save claim info with instance claimInfo.paidAmount = claimInfo.paidAmount.add(payoutAmount); claimInfo.openPayoutsCount -= 1; @@ -371,29 +377,31 @@ contract ClaimService is claimInfo.closedAt = TimestampLib.blockTimestamp(); instanceStore.updateClaim(policyNftId, claimId, claimInfo, CLOSED()); + // update and save policy info with instance policyInfo.openClaimsCount -= 1; + policyInfo.payoutAmount = policyInfo.payoutAmount + payoutAmount; + instanceStore.updatePolicyClaims(policyNftId, policyInfo, KEEP_STATE()); } else { instanceStore.updateClaim(policyNftId, claimId, claimInfo, KEEP_STATE()); } } - // update and save policy info with instance - policyInfo.payoutAmount = policyInfo.payoutAmount + payoutAmount; - instanceStore.updatePolicyClaims(policyNftId, policyInfo, KEEP_STATE()); - emit LogClaimServicePayoutProcessed(policyNftId, payoutId, payoutAmount); // effects + interactions (push tokens to beneficiary, product) // delegate to pool to update book keeping and moving tokens payout - (netPayoutAmount, processingFeeAmount) = _poolService.processPayout( - instanceReader, - instanceStore, - policyInfo.productNftId, // product nft id - policyNftId, - policyInfo.bundleNftId, - payoutId, - payoutAmount, - payoutBeneficiary); + { + ClaimServiceStorage storage $ = _getClaimServiceStorage(); + (netPayoutAmount, processingFeeAmount) = $._poolService.processPayout( + instanceReader, + instanceStore, + policyInfo.productNftId, // product nft id + policyNftId, + policyInfo.bundleNftId, + payoutId, + payoutAmount, + payoutBeneficiary); + } } function cancelPayout( @@ -409,6 +417,7 @@ contract ClaimService is ,, InstanceReader instanceReader, InstanceStore instanceStore, + //IPolicy.PolicyInfo memory policyInfo ) = _verifyCallerWithPolicy(policyNftId); StateId payoutState = instanceReader.getPayoutState(policyNftId, payoutId); @@ -634,6 +643,12 @@ contract ClaimService is } } + function _getClaimServiceStorage() private pure returns (ClaimServiceStorage storage $) { + // solhint-disable-next-line no-inline-assembly + assembly { + $.slot := CLAIM_SERVICE_STORAGE_LOCATION_V3_0 + } + } function _getDomain() internal pure override returns(ObjectType) { return CLAIM(); diff --git a/contracts/product/PolicyService.sol b/contracts/product/PolicyService.sol index 6e07d940e..80d924ff3 100644 --- a/contracts/product/PolicyService.sol +++ b/contracts/product/PolicyService.sol @@ -33,11 +33,16 @@ contract PolicyService is Service, IPolicyService { - IAccountingService private _accountingService; - IComponentService internal _componentService; - IDistributionService internal _distributionService; - IPoolService internal _poolService; - IPricingService internal _pricingService; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.PolicyService@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant POLICY_SERVICE_STORAGE_LOCATION_V3_0 = 0x862c7110061e72e577b74a9231a4d5d6d7c0698598767dc8092f941bca614500; + + struct PolicyServiceStorage { + IAccountingService _accountingService; + IComponentService _componentService; + IDistributionService _distributionService; + IPoolService _poolService; + IPricingService _pricingService; + } function _initialize( address owner, @@ -55,11 +60,12 @@ contract PolicyService is __Service_init(authority, registry, owner); VersionPart majorVersion = getVersion().toMajorPart(); - _accountingService = IAccountingService(getRegistry().getServiceAddress(ACCOUNTING(), majorVersion)); - _componentService = IComponentService(getRegistry().getServiceAddress(COMPONENT(), majorVersion)); - _poolService = IPoolService(getRegistry().getServiceAddress(POOL(), majorVersion)); - _distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion)); - _pricingService = IPricingService(getRegistry().getServiceAddress(PRICE(), majorVersion)); + PolicyServiceStorage storage $ = _getPolicyServiceStorage(); + $._accountingService = IAccountingService(getRegistry().getServiceAddress(ACCOUNTING(), majorVersion)); + $._componentService = IComponentService(getRegistry().getServiceAddress(COMPONENT(), majorVersion)); + $._poolService = IPoolService(getRegistry().getServiceAddress(POOL(), majorVersion)); + $._distributionService = IDistributionService(getRegistry().getServiceAddress(DISTRIBUTION(), majorVersion)); + $._pricingService = IPricingService(getRegistry().getServiceAddress(PRICE(), majorVersion)); _registerInterface(type(IPolicyService).interfaceId); } @@ -116,69 +122,83 @@ contract PolicyService is revert ErrorPolicyServicePolicyStateNotApplied(applicationNftId); } - // effects - // actual collateralizaion - _poolService.lockCollateral( - instance, - address(instanceReader.getToken(productNftId)), - productNftId, - applicationNftId, - applicationInfo.bundleNftId, - applicationInfo.sumInsuredAmount); + PolicyServiceStorage storage $ = _getPolicyServiceStorage(); - // optional activation of policy - if(activateAt.gtz()) { - applicationInfo = PolicyServiceLib.activate(applicationNftId, applicationInfo, activateAt); - } + { + RiskId riskId = applicationInfo.riskId; + NftId bundleNftId = applicationInfo.bundleNftId; + + { + // calculate premium + IPolicy.PremiumInfo memory premium = $._pricingService.calculatePremium( + productNftId, + riskId, + applicationInfo.sumInsuredAmount, + applicationInfo.lifetime, + applicationInfo.applicationData, + bundleNftId, + applicationInfo.referralId); - // update policy and set state to collateralized - instance.getInstanceStore().updatePolicy( - applicationNftId, - applicationInfo, - COLLATERALIZED()); - - // calculate and store premium - RiskId riskId = applicationInfo.riskId; - NftId bundleNftId = applicationInfo.bundleNftId; - - IPolicy.PremiumInfo memory premium = _pricingService.calculatePremium( - productNftId, - riskId, - applicationInfo.sumInsuredAmount, - applicationInfo.lifetime, - applicationInfo.applicationData, - bundleNftId, - applicationInfo.referralId); - - if (premium.premiumAmount > maxPremiumAmount) { - revert LogPolicyServiceMaxPremiumAmountExceeded( + premiumAmount = premium.premiumAmount; + + // check calculated premium does not exceed max premium amount + if (premiumAmount > maxPremiumAmount) { + revert LogPolicyServiceMaxPremiumAmountExceeded( + applicationNftId, + maxPremiumAmount, + premiumAmount); + } + + // create premium in instance + instance.getInstanceStore().createPremium( + applicationNftId, + premium); + } + + // optional activation of policy + if(activateAt.gtz()) { + applicationInfo = PolicyServiceLib.activate(applicationNftId, applicationInfo, activateAt); + } + + // TODO do not write applicationInfo if no changes where made -> add/use updatePolicyState() + // update policy and set state to collateralized + instance.getInstanceStore().updatePolicy( applicationNftId, - maxPremiumAmount, - premium.premiumAmount); - } + applicationInfo, + COLLATERALIZED()); + + // link policy to risk and bundle + { + NftId poolNftId = getRegistry().getParentNftId(bundleNftId); + instance.getRiskSet().linkPolicy(productNftId, riskId, applicationNftId); + instance.getBundleSet().linkPolicy( + poolNftId,//getRegistry().getParentNftId(bundleNftId), + bundleNftId, + applicationNftId); + } - premiumAmount = premium.premiumAmount; - instance.getInstanceStore().createPremium( - applicationNftId, - premium); + // actual collateralizaion + $._poolService.lockCollateral( + instance, + address(instanceReader.getToken(productNftId)), + productNftId, + applicationNftId, + bundleNftId, + applicationInfo.sumInsuredAmount); + } - // update referral counter if product has linked distributino component + // update referral counter if product has linked distribution component { IComponents.ProductInfo memory productInfo = instanceReader.getProductInfo(productNftId); if (productInfo.hasDistribution) { - _distributionService.processReferral( + $._distributionService.processReferral( productInfo.distributionNftId, applicationInfo.referralId); } } - // link policy to risk and bundle - NftId poolNftId = getRegistry().getParentNftId(bundleNftId); - instance.getRiskSet().linkPolicy(productNftId, riskId, applicationNftId); - instance.getBundleSet().linkPolicy(poolNftId, bundleNftId, applicationNftId); - // log policy creation before interactions with token and policy holder - emit LogPolicyServicePolicyCreated(applicationNftId, premium.premiumAmount, activateAt); + emit LogPolicyServicePolicyCreated(applicationNftId, premiumAmount, activateAt); // interactions // callback to policy holder if applicable @@ -404,9 +424,11 @@ contract PolicyService is revert ErrorPolicyServicePremiumNotPaid(policyNftId, policyInfo.premiumAmount); } + PolicyServiceStorage storage $ = _getPolicyServiceStorage(); + // effects // release (remaining) collateral that was blocked by policy - _poolService.releaseCollateral( + $._poolService.releaseCollateral( instance, policyNftId, policyInfo); @@ -469,22 +491,24 @@ contract PolicyService is instanceReader, productNftId); + PolicyServiceStorage storage $ = _getPolicyServiceStorage(); + // update product fees, distribution and pool fees - _accountingService.increaseProductFees( + $._accountingService.increaseProductFees( instanceStore, productNftId, premium.productFeeVarAmount + premium.productFeeFixAmount); // update distribution fees and distributor commission and pool fees if (!distributionNftId.eqz()) { // only call distribution service if a distribution component is connected to the product - _distributionService.processSale( + $._distributionService.processSale( distributionNftId, referralId, premium); } // update pool and bundle fees - _poolService.processSale( + $._poolService.processSale( bundleNftId, premium); } @@ -638,6 +662,13 @@ contract PolicyService is } } + function _getPolicyServiceStorage() private pure returns (PolicyServiceStorage storage $) { + // solhint-disable-next-line no-inline-assembly + assembly { + $.slot := POLICY_SERVICE_STORAGE_LOCATION_V3_0 + } + } + function _getDomain() internal pure override returns(ObjectType) { return POLICY(); diff --git a/contracts/product/PricingService.sol b/contracts/product/PricingService.sol index fc0f7dfd4..b887202b6 100644 --- a/contracts/product/PricingService.sol +++ b/contracts/product/PricingService.sol @@ -28,7 +28,12 @@ contract PricingService is Service, IPricingService { - IDistributionService internal _distributionService; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.PricingService@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant PRICING_SERVICE_STORAGE_LOCATION_V3_0 = 0x69339118ac24f243948ace3f64dcbea8699f7f0061492066c280ac597f7bd500; + + struct PricingServiceStorage { + IDistributionService _distributionService; + } function _initialize( address owner, @@ -45,7 +50,8 @@ contract PricingService is __Service_init(authority, registry, owner); - _distributionService = IDistributionService(_getServiceAddress(DISTRIBUTION())); + PricingServiceStorage storage $ = _getPricingServiceStorage(); + $._distributionService = IDistributionService(_getServiceAddress(DISTRIBUTION())); _registerInterface(type(IPricingService).interfaceId); } @@ -243,9 +249,9 @@ contract PricingService is view returns (IPolicy.PremiumInfo memory finalPremium) { - + PricingServiceStorage storage $ = _getPricingServiceStorage(); // if the referral is not valid, then the distribution owner gets everything - if (distributionNftId.eqz() || ! _distributionService.referralIsValid(distributionNftId, referralId)) { + if (distributionNftId.eqz() || ! $._distributionService.referralIsValid(distributionNftId, referralId)) { premium.distributionOwnerFeeFixAmount = premium.distributionFeeFixAmount; premium.distributionOwnerFeeVarAmount = premium.distributionFeeVarAmount; premium.premiumAmount = premium.fullPremiumAmount; @@ -254,7 +260,7 @@ contract PricingService is Fee memory minDistributionOwnerFee = feeInfo.minDistributionOwnerFee; - // if the referral is valid, the the commission and discount are calculated based in the full premium + // if the referral is valid, then the commission and discount are calculated based in the full premium // the remaing amount goes to the distribution owner { IDistribution.ReferralInfo memory referralInfo = reader.getReferralInfo(referralId); @@ -299,6 +305,12 @@ contract PricingService is premiumWithTargetWalletAmounts = premium; } + function _getPricingServiceStorage() private pure returns (PricingServiceStorage storage $) { + // solhint-disable-next-line no-inline-assembly + assembly { + $.slot := PRICING_SERVICE_STORAGE_LOCATION_V3_0 + } + } function _getDomain() internal pure override returns(ObjectType) { return PRICE(); diff --git a/contracts/product/Product.sol b/contracts/product/Product.sol index a865c1f01..5f9247a2f 100644 --- a/contracts/product/Product.sol +++ b/contracts/product/Product.sol @@ -30,8 +30,8 @@ abstract contract Product is InstanceLinkedComponent, IProductComponent { - // keccak256(abi.encode(uint256(keccak256("etherisc.storage.Product")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant PRODUCT_STORAGE_LOCATION_V1 = 0x0bb7aafdb8e380f81267337bc5b5dfdf76e6d3a380ecadb51ec665246d9d6800; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.Product@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant PRODUCT_STORAGE_LOCATION_V3_0 = 0x3261127dd9d5619cc84045fb5cff6ef7871eb2df664d756420362d0f872a4600; struct ProductStorage { IComponents.ProductInfo _productInfo; @@ -466,7 +466,7 @@ abstract contract Product is function _getProductStorage() internal virtual pure returns (ProductStorage storage $) { assembly { - $.slot := PRODUCT_STORAGE_LOCATION_V1 + $.slot := PRODUCT_STORAGE_LOCATION_V3_0 } } } \ No newline at end of file diff --git a/contracts/shared/Component.sol b/contracts/shared/Component.sol index e2c9b72ee..7c3faa6cc 100644 --- a/contracts/shared/Component.sol +++ b/contracts/shared/Component.sol @@ -19,8 +19,8 @@ abstract contract Component is Registerable, IComponent { - // keccak256(abi.encode(uint256(keccak256("gif-next.contracts.component.Component.sol")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant COMPONENT_LOCATION_V1 = 0xffe8d4462baed26a47154f4b8f6db497d2f772496965791d25bd456e342b7f00; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.Component@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant COMPONENT_STORAGE_LOCATION_V3_0 = 0xfc96c0569508c55c4a252d7e9dd1f9d0347413a3bb20065fd534643ada195b00; struct ComponentStorage { string _name; // unique (per instance) component name @@ -41,7 +41,7 @@ abstract contract Component is function _getComponentStorage() private pure returns (ComponentStorage storage $) { // solhint-disable-next-line no-inline-assembly assembly { - $.slot := COMPONENT_LOCATION_V1 + $.slot := COMPONENT_STORAGE_LOCATION_V3_0 } } diff --git a/contracts/shared/ComponentService.sol b/contracts/shared/ComponentService.sol index 2a2035a57..c0e1d6958 100644 --- a/contracts/shared/ComponentService.sol +++ b/contracts/shared/ComponentService.sol @@ -36,9 +36,14 @@ contract ComponentService is bool private constant INCREASE = true; bool private constant DECREASE = false; - IAccountingService private _accountingService; - IRegistryService private _registryService; - IInstanceService private _instanceService; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.ComponentService@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant COMPONENT_SERVICE_STORAGE_LOCATION_V3_0 = 0xc5533ae48eb96dccabcb7c228b271a453799a15cdbe5e61ead04b4ec1b7d9c00; + + struct ComponentServiceStorage { + IAccountingService _accountingService; + IRegistryService _registryService; + IInstanceService _instanceService; + } function _initialize( address owner, @@ -55,9 +60,10 @@ contract ComponentService is __Service_init(authority, registry, owner); - _accountingService = IAccountingService(_getServiceAddress(ACCOUNTING())); - _registryService = IRegistryService(_getServiceAddress(REGISTRY())); - _instanceService = IInstanceService(_getServiceAddress(INSTANCE())); + ComponentServiceStorage storage $ = _getComponentServiceStorage(); + $._accountingService = IAccountingService(_getServiceAddress(ACCOUNTING())); + $._registryService = IRegistryService(_getServiceAddress(REGISTRY())); + $._instanceService = IInstanceService(_getServiceAddress(INSTANCE())); _registerInterface(type(IComponentService).interfaceId); } @@ -175,7 +181,8 @@ contract ComponentService is // effects // decrease fee counters by withdrawnAmount - _accountingService.decreaseComponentFees( + ComponentServiceStorage storage $ = _getComponentServiceStorage(); + $._accountingService.decreaseComponentFees( instance.getInstanceStore(), componentNftId, withdrawnAmount); @@ -485,14 +492,13 @@ contract ComponentService is componentAddress, parentNftId); - InstanceAdmin instanceAdmin = instance.getInstanceAdmin(); InstanceStore instanceStore = instance.getInstanceStore(); - InstanceReader instanceReader = instance.getInstanceReader(); ObjectType componentType = objectInfo.objectType; + ComponentServiceStorage storage $ = _getComponentServiceStorage(); if(componentType == PRODUCT()) { // register product with registry - componentNftId = _registryService.registerProduct( + componentNftId = $._registryService.registerProduct( component, objectInfo.initialOwner).nftId; @@ -500,13 +506,14 @@ contract ComponentService is _createProduct(instanceStore, componentNftId, componentAddress); } else { // register non product component with registry - componentNftId = _registryService.registerProductLinkedComponent( + componentNftId = $._registryService.registerProductLinkedComponent( component, objectInfo.objectType, objectInfo.initialOwner).nftId; // create non product component info in instance store NftId productNftId = parentNftId; + InstanceReader instanceReader = instance.getInstanceReader(); IComponents.ProductInfo memory productInfo = instanceReader.getProductInfo(productNftId); if(componentType == POOL()) { _createPool(instanceStore, productNftId, componentNftId, componentAddress, productInfo); @@ -525,6 +532,7 @@ contract ComponentService is _checkToken(instance, token); // deploy and wire token handler + InstanceAdmin instanceAdmin = instance.getInstanceAdmin(); IComponents.ComponentInfo memory componentInfo = component.getInitialComponentInfo(); componentInfo.tokenHandler = TokenHandlerDeployerLib.deployTokenHandler( address(getRegistry()), @@ -547,7 +555,7 @@ contract ComponentService is instance.getNftId(), componentNftId, componentType, - address(component), + componentAddress, token, objectInfo.initialOwner); } @@ -672,6 +680,12 @@ contract ComponentService is instance = IInstance(instanceAddress); } + function _getComponentServiceStorage() private pure returns (ComponentServiceStorage storage $) { + // solhint-disable-next-line no-inline-assembly + assembly { + $.slot := COMPONENT_SERVICE_STORAGE_LOCATION_V3_0 + } + } function _getDomain() internal pure virtual override returns(ObjectType) { return COMPONENT(); diff --git a/contracts/shared/InitializableERC165.sol b/contracts/shared/InitializableERC165.sol index 11750040a..1f1dee4c3 100644 --- a/contracts/shared/InitializableERC165.sol +++ b/contracts/shared/InitializableERC165.sol @@ -8,7 +8,12 @@ contract InitializableERC165 is Initializable, IERC165 { - mapping(bytes4 => bool) private _isSupported; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.InitializableERC165@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant INITIALIZABLE_ERC165_STORAGE_LOCATION_V3_0 = 0x2c5de3b4947d23a15785cdf804e1e581a3c5f54c0357f66e3f442def0f390100; + + struct InitializableERC165Storage { + mapping(bytes4 => bool) _isSupported; + } // @dev initializes with support for ERC165 function __ERC165_init() internal onlyInitializing() { @@ -16,7 +21,8 @@ contract InitializableERC165 is } function _initializeERC165() internal { - _isSupported[type(IERC165).interfaceId] = true; + InitializableERC165Storage storage $ = _getInitializableERC165Storage(); + $._isSupported[type(IERC165).interfaceId] = true; } // @dev register support for provided interfaceId @@ -26,10 +32,18 @@ contract InitializableERC165 is } function _registerInterfaceNotInitializing(bytes4 interfaceId) internal{ - _isSupported[interfaceId] = true; + InitializableERC165Storage storage $ = _getInitializableERC165Storage(); + $._isSupported[interfaceId] = true; } function supportsInterface(bytes4 interfaceId) external view override returns (bool) { - return _isSupported[interfaceId]; + InitializableERC165Storage storage $ = _getInitializableERC165Storage(); + return $._isSupported[interfaceId]; + } + + function _getInitializableERC165Storage() private pure returns (InitializableERC165Storage storage $) { + assembly { + $.slot := INITIALIZABLE_ERC165_STORAGE_LOCATION_V3_0 + } } } \ No newline at end of file diff --git a/contracts/shared/InstanceLinkedComponent.sol b/contracts/shared/InstanceLinkedComponent.sol index c1074bf2d..e4ea12ce9 100644 --- a/contracts/shared/InstanceLinkedComponent.sol +++ b/contracts/shared/InstanceLinkedComponent.sol @@ -30,8 +30,8 @@ abstract contract InstanceLinkedComponent is Component, IInstanceLinkedComponent { - // keccak256(abi.encode(uint256(keccak256("gif-next.contracts.component.Component.sol")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant INSTANCE_LINKED_COMPONENT_LOCATION_V1 = 0xffe3d4462bded26a47154f4b8f6db494d2f772496965791d25bd456e342b7f00; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.InstanceLinkedComponent@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant INSTANCE_LINKED_COMPONENT_STORAGE_LOCATION_V3_0 = 0xdc3a75afc3e621184afdbd532600dd89ad5b8ed15ddda6ef096bf0aad1761400; struct InstanceLinkedComponentStorage { IInstance _instance; // instance for this component @@ -63,7 +63,7 @@ abstract contract InstanceLinkedComponent is function _getInstanceLinkedComponentStorage() private pure returns (InstanceLinkedComponentStorage storage $) { assembly { - $.slot := INSTANCE_LINKED_COMPONENT_LOCATION_V1 + $.slot := INSTANCE_LINKED_COMPONENT_STORAGE_LOCATION_V3_0 } } diff --git a/contracts/shared/NftOwnable.sol b/contracts/shared/NftOwnable.sol index 0caf8dc05..74290d5ce 100644 --- a/contracts/shared/NftOwnable.sol +++ b/contracts/shared/NftOwnable.sol @@ -12,8 +12,8 @@ contract NftOwnable is RegistryLinked, INftOwnable { - // keccak256(abi.encode(uint256(keccak256("etherisc.storage.NftOwnable")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant NFT_OWNABLE_STORAGE_LOCATION_V1 = 0x07ebcf49758b6ed3af50fa146bec0abe157c0218fe65dc0874c286e9d5da4f00; + // keccak256(abi.encode(uint256(keccak256("etherisc.storage.NftOwnable@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant NFT_OWNABLE_STORAGE_LOCATION_V3_0 = 0x75a854a54bf614cac5ba72c2235143229b43a26f8eb448270fb97a467532e300; struct NftOwnableStorage { NftId _nftId; @@ -123,7 +123,7 @@ contract NftOwnable is function _getNftOwnableStorage() private pure returns (NftOwnableStorage storage $) { // solhint-disable-next-line no-inline-assembly assembly { - $.slot := NFT_OWNABLE_STORAGE_LOCATION_V1 + $.slot := NFT_OWNABLE_STORAGE_LOCATION_V3_0 } } } \ No newline at end of file diff --git a/contracts/shared/Registerable.sol b/contracts/shared/Registerable.sol index 870c00471..92de20983 100644 --- a/contracts/shared/Registerable.sol +++ b/contracts/shared/Registerable.sol @@ -20,8 +20,8 @@ abstract contract Registerable is NftOwnable, IRegisterable { - // keccak256(abi.encode(uint256(keccak256("gif-next.contracts.shared.Registerable.sol")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant REGISTERABLE_LOCATION_V1 = 0x6548007c3f4340f82f348c576c0ff69f4f529cadd5ad41f96aae61abceeaa300; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.Registerable@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant REGISTERABLE_STORAGE_LOCATION_V3_0 = 0x66ed5788a8bec6ff1e7b389e8e939876404dd6c85eb5e16ebccc687f21cd6200; struct RegisterableStorage { NftId _parentNftId; @@ -100,7 +100,7 @@ abstract contract Registerable is function _getRegisterableStorage() private pure returns (RegisterableStorage storage $) { assembly { - $.slot := REGISTERABLE_LOCATION_V1 + $.slot := REGISTERABLE_STORAGE_LOCATION_V3_0 } } } \ No newline at end of file diff --git a/contracts/staking/Staking.sol b/contracts/staking/Staking.sol index f748e16ff..a28a6a930 100644 --- a/contracts/staking/Staking.sol +++ b/contracts/staking/Staking.sol @@ -35,8 +35,8 @@ contract Staking is { string public constant CONTRACT_NAME = "Staking"; - // keccak256(abi.encode(uint256(keccak256("gif-next.contracts.component.Staking.sol")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant STAKING_LOCATION_V1 = 0xafe8d4462b2ed26a47154f4b8f6d1497d2f772496965791d25bd456e342b7f00; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.Staking@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant STAKING_STORAGE_LOCATION_V3_0 = 0x17325792392c6ffb9e46de8a113aab40b12e7804b80f435c7c40612bd5653400; struct StakingStorage { TokenRegistry _tokenRegistry; @@ -599,7 +599,7 @@ contract Staking is function _getStakingStorage() private pure returns (StakingStorage storage $) { assembly { - $.slot := STAKING_LOCATION_V1 + $.slot := STAKING_STORAGE_LOCATION_V3_0 } } } diff --git a/contracts/staking/StakingService.sol b/contracts/staking/StakingService.sol index a362c038b..cfe01ce17 100644 --- a/contracts/staking/StakingService.sol +++ b/contracts/staking/StakingService.sol @@ -23,8 +23,8 @@ contract StakingService is IStakingService { // TODO decide and implement string spec for location calculation - // keccak256(abi.encode(uint256(keccak256("gif-next.contracts.shared.StakingService.sol")) - 1)) & ~bytes32(uint256(0xff)); - bytes32 public constant STAKING_SERVICE_LOCATION_V1 = 0x6548005c3f4340f82f348c576c0ff69f7f529cadd5ad41f96aae61abceeaa300; + // keccak256(abi.encode(uint256(keccak256("etherisc.gif.StakingService@3.0.0")) - 1)) & ~bytes32(uint256(0xff)); + bytes32 public constant STAKING_SERVICE_STORAGE_LOCATION_V3_0 = 0x5744a630cd832cc833bbcbacd41a5b85ea7e62a359f2b0312fec3efecead1700; struct StakingServiceStorage { RegistryService _registryService; @@ -457,7 +457,7 @@ contract StakingService is function _getStakingServiceStorage() private pure returns (StakingServiceStorage storage $) { assembly { - $.slot := STAKING_SERVICE_LOCATION_V1 + $.slot := STAKING_SERVICE_STORAGE_LOCATION_V3_0 } }