diff --git a/contracts/instance/base/BalanceStore.sol b/contracts/instance/base/BalanceStore.sol index afdca236a..8e63f44f1 100644 --- a/contracts/instance/base/BalanceStore.sol +++ b/contracts/instance/base/BalanceStore.sol @@ -116,6 +116,6 @@ contract BalanceStore { //--- internal/private functions ----------------------------------------// function _setLastUpdatedIn(NftId targetNftId) internal { - _lastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber(); + _lastUpdatedIn[targetNftId] = BlocknumberLib.current(); } } diff --git a/contracts/shared/IKeyValueStore.sol b/contracts/shared/IKeyValueStore.sol index f96621345..b8bbaee22 100644 --- a/contracts/shared/IKeyValueStore.sol +++ b/contracts/shared/IKeyValueStore.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.20; -import {Blocknumber, blockBlocknumber, zeroBlocknumber} from "../type/Blocknumber.sol"; +import {Blocknumber} from "../type/Blocknumber.sol"; import {Key32, KeyId} from "../type/Key32.sol"; import {NftId} from "../type/NftId.sol"; import {ObjectType} from "../type/ObjectType.sol"; diff --git a/contracts/shared/KeyValueStore.sol b/contracts/shared/KeyValueStore.sol index 85b8bab86..005387162 100644 --- a/contracts/shared/KeyValueStore.sol +++ b/contracts/shared/KeyValueStore.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.20; -import {Blocknumber, blockBlocknumber, zeroBlocknumber} from "../type/Blocknumber.sol"; +import {Blocknumber, BlocknumberLib} from "../type/Blocknumber.sol"; import {Key32, KeyId, Key32Lib} from "../type/Key32.sol"; import {NftId} from "../type/NftId.sol"; import {ObjectType} from "../type/ObjectType.sol"; @@ -38,7 +38,7 @@ abstract contract KeyValueStore is revert ErrorKeyValueStoreNoLifecycle(objectType); } - Blocknumber blocknumber = blockBlocknumber(); + Blocknumber blocknumber = BlocknumberLib.current(); StateId initialState = getInitialState(objectType); // set metadata @@ -102,7 +102,7 @@ abstract contract KeyValueStore is } // update metadata - metadata.updatedIn = blockBlocknumber(); + metadata.updatedIn = BlocknumberLib.current(); } function exists(Key32 key32) public view returns (bool) { diff --git a/contracts/staking/StakingStore.sol b/contracts/staking/StakingStore.sol index 93c5b4a78..b4e9c353d 100644 --- a/contracts/staking/StakingStore.sol +++ b/contracts/staking/StakingStore.sol @@ -118,7 +118,7 @@ contract StakingStore is } info.stakingRate = UFixedLib.zero(); - info.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + info.lastUpdatedIn = BlocknumberLib.current(); } @@ -146,7 +146,7 @@ contract StakingStore is // update values info.stakingRate = stakingRate; - info.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + info.lastUpdatedIn = BlocknumberLib.current(); } //--- target management -------------------------------------------------// @@ -236,7 +236,7 @@ contract StakingStore is // checks targetInfo = _getAndVerifyTarget(targetNftId); lastUpdatedIn = targetInfo.lastUpdatedIn; - targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + targetInfo.lastUpdatedIn = BlocknumberLib.current(); } @@ -272,7 +272,7 @@ contract StakingStore is targetInfo.lockingPeriod = lockingPeriod; targetInfo.rewardRate = rewardRate; targetInfo.chainId = ChainIdLib.fromNftId(targetNftId); - targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + targetInfo.lastUpdatedIn = BlocknumberLib.current(); // add new target to target set _targetNftIdSet.add(targetNftId); @@ -305,7 +305,7 @@ contract StakingStore is // effects tvlInfo.tvlAmount = AmountLib.zero(); - tvlInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + tvlInfo.lastUpdatedIn = BlocknumberLib.current(); // add token to list of know tokens for target _targetToken[targetNftId].push(token); @@ -325,7 +325,7 @@ contract StakingStore is // effects targetInfo.reserveAmount = targetInfo.reserveAmount + dipAmount; - targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + targetInfo.lastUpdatedIn = BlocknumberLib.current(); newReserveBalance = targetInfo.reserveAmount; } @@ -351,7 +351,7 @@ contract StakingStore is // effects targetInfo.reserveAmount = targetInfo.reserveAmount - dipAmount; - targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + targetInfo.lastUpdatedIn = BlocknumberLib.current(); newReserveBalance = targetInfo.reserveAmount; } @@ -372,7 +372,7 @@ contract StakingStore is // effects tvlInfo.tvlAmount = tvlInfo.tvlAmount + amount; - tvlInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + tvlInfo.lastUpdatedIn = BlocknumberLib.current(); newBalance = tvlInfo.tvlAmount; } @@ -391,7 +391,7 @@ contract StakingStore is // effects tvlInfo.tvlAmount = tvlInfo.tvlAmount - amount; - tvlInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + tvlInfo.lastUpdatedIn = BlocknumberLib.current(); newBalance = tvlInfo.tvlAmount; } @@ -422,7 +422,7 @@ contract StakingStore is // effects // update target targetInfo.stakedAmount = stakedAmount; - targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + targetInfo.lastUpdatedIn = BlocknumberLib.current(); // update stake stakeInfo.targetNftId = targetNftId; @@ -430,7 +430,7 @@ contract StakingStore is stakeInfo.rewardAmount = AmountLib.zero(); stakeInfo.lockedUntil = lockedUntil; stakeInfo.lastUpdateAt = TimestampLib.current(); - stakeInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + stakeInfo.lastUpdatedIn = BlocknumberLib.current(); } @@ -452,13 +452,13 @@ contract StakingStore is // update target targetInfo.stakedAmount = targetInfo.stakedAmount + stakedAmount; targetInfo.rewardAmount = targetInfo.rewardAmount + rewardAmount; - targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + targetInfo.lastUpdatedIn = BlocknumberLib.current(); // update stake stakeInfo.stakedAmount = stakeInfo.stakedAmount + stakedAmount; stakeInfo.rewardAmount = stakeInfo.rewardAmount + rewardAmount; stakeInfo.lastUpdateAt = TimestampLib.current(); - stakeInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + stakeInfo.lastUpdatedIn = BlocknumberLib.current(); // increase locked until if applicable if (additionalLockingPeriod.gtz()) { @@ -491,13 +491,13 @@ contract StakingStore is targetInfo.stakedAmount = targetInfo.stakedAmount - unstakedAmount; targetInfo.rewardAmount = targetInfo.rewardAmount - claimedAmount; targetInfo.reserveAmount = targetInfo.reserveAmount - claimedAmount; - targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + targetInfo.lastUpdatedIn = BlocknumberLib.current(); // update stake stakeInfo.stakedAmount = stakeInfo.stakedAmount - unstakedAmount; stakeInfo.rewardAmount = stakeInfo.rewardAmount - claimedAmount; stakeInfo.lastUpdateAt = TimestampLib.current(); - stakeInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + stakeInfo.lastUpdatedIn = BlocknumberLib.current(); } @@ -525,13 +525,13 @@ contract StakingStore is // update target targetInfo.stakedAmount = targetInfo.stakedAmount + updatedRewardAmount; targetInfo.rewardAmount = targetInfo.rewardAmount - oldRewardAmount; - targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + targetInfo.lastUpdatedIn = BlocknumberLib.current(); // update stake stakeInfo.stakedAmount = stakeInfo.stakedAmount + updatedRewardAmount; stakeInfo.rewardAmount = AmountLib.zero(); stakeInfo.lastUpdateAt = TimestampLib.current(); - stakeInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + stakeInfo.lastUpdatedIn = BlocknumberLib.current(); // increase locked until if applicable if (additionalLockingPeriod.gtz()) { @@ -672,7 +672,7 @@ contract StakingStore is // set tvl balances to 0 and update last updated in info.tvlAmount = AmountLib.zero(); - info.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + info.lastUpdatedIn = BlocknumberLib.current(); } @@ -692,7 +692,7 @@ contract StakingStore is lastUpdatedIn = tvlInfo.lastUpdatedIn; tvlInfo.tvlAmount = newTvlAmount; - tvlInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber(); + tvlInfo.lastUpdatedIn = BlocknumberLib.current(); } diff --git a/contracts/type/Blocknumber.sol b/contracts/type/Blocknumber.sol index 73fc3b669..2b8087f12 100644 --- a/contracts/type/Blocknumber.sol +++ b/contracts/type/Blocknumber.sol @@ -58,15 +58,16 @@ function toBlocknumber(uint256 blocknum) pure returns (Blocknumber) { return Blocknumber.wrap(uint32(blocknum)); } -function blockBlocknumber() view returns (Blocknumber) { - return BlocknumberLib.currentBlocknumber(); -} +// TODO cleanup +// function blockBlocknumber() view returns (Blocknumber) { +// return BlocknumberLib.currentBlocknumber(); +// } -// TODO move to BlocknumberLib and rename to zero() -/// @dev Return the Blocknumber zero (0) -function zeroBlocknumber() pure returns (Blocknumber) { - return toBlocknumber(0); -} +// // TODO move to BlocknumberLib and rename to zero() +// /// @dev Return the Blocknumber zero (0) +// function zeroBlocknumber() pure returns (Blocknumber) { +// return toBlocknumber(0); +// } /// @dev Return the current block number function blockNumber() view returns (Blocknumber) { @@ -87,10 +88,11 @@ library BlocknumberLib { return Blocknumber.wrap(uint40(block.number)); } - /// @dev returns the current Blocknumber - function currentBlocknumber() public view returns (Blocknumber) { - return Blocknumber.wrap(uint32(block.number)); - } + // TODO cleanup + // /// @dev returns the current Blocknumber + // function currentBlocknumber() public view returns (Blocknumber) { + // return current(); + // } /// @dev return true iff blocknumber is 0 function eqz(Blocknumber blocknumber) public pure returns (bool) { diff --git a/contracts/type/Timestamp.sol b/contracts/type/Timestamp.sol index 3716011df..f482b4874 100644 --- a/contracts/type/Timestamp.sol +++ b/contracts/type/Timestamp.sol @@ -76,11 +76,6 @@ library TimestampLib { return Timestamp.wrap(uint40(block.timestamp)); } - // TODO cleanup - // function blockTimestamp() public view returns (Timestamp) { - // return current(); - // } - function toTimestamp(uint256 timestamp) public pure returns (Timestamp) { return Timestamp.wrap(uint40(timestamp)); } diff --git a/test/staking/TvlCalculation.t.sol b/test/staking/TvlCalculation.t.sol index 37be1c293..8bf9244b1 100644 --- a/test/staking/TvlCalculation.t.sol +++ b/test/staking/TvlCalculation.t.sol @@ -97,7 +97,7 @@ contract TvlCalculation is GifTest { // WHEN collateralizing the application // check tvl log entry from staking - Blocknumber currentBlocknumber = BlocknumberLib.currentBlocknumber(); + Blocknumber currentBlocknumber = BlocknumberLib.current(); Timestamp currentTimestamp = TimestampLib.current(); vm.expectEmit(stakingStoreAddress); emit LogStakingStoreTotalValueLockedIncreased( @@ -167,7 +167,7 @@ contract TvlCalculation is GifTest { vm.warp(policyExpiryAt.toInt()); // check tvl decrease log emission - Blocknumber currentBlocknumber = BlocknumberLib.currentBlocknumber(); + Blocknumber currentBlocknumber = BlocknumberLib.current(); Amount zeroAmount = AmountLib.zero(); vm.expectEmit(stakingStoreAddress); emit LogStakingStoreTotalValueLockedDecreased( @@ -302,7 +302,7 @@ contract TvlCalculation is GifTest { "unexpected required stake balance (after payout creation)"); // WHEN processing the payout (includes actual payout token flow) - Blocknumber currentBlocknumber = BlocknumberLib.currentBlocknumber(); + Blocknumber currentBlocknumber = BlocknumberLib.current(); Amount newBalanceAmount = sumInsuredAmount - claimAmount; vm.expectEmit(stakingStoreAddress); emit LogStakingStoreTotalValueLockedDecreased( diff --git a/test/type/Blocknumber.t.sol b/test/type/Blocknumber.t.sol index 7080906f0..97636df76 100644 --- a/test/type/Blocknumber.t.sol +++ b/test/type/Blocknumber.t.sol @@ -1,7 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 pragma solidity ^0.8.20; -import {Blocknumber, BlocknumberLib, neBlocknumber, eqBlocknumber, gtBlocknumber, gteBlocknumber, ltBlocknumber, lteBlocknumber, toBlocknumber, zeroBlocknumber, blockBlocknumber} from "../../contracts/type/Blocknumber.sol"; +import {Blocknumber, BlocknumberLib, neBlocknumber, eqBlocknumber, gtBlocknumber, gteBlocknumber, ltBlocknumber, lteBlocknumber, toBlocknumber} from "../../contracts/type/Blocknumber.sol"; import {Test} from "../../lib/forge-std/src/Test.sol"; @@ -23,17 +23,17 @@ contract BlocknumberTest is Test { } function test_zeroBlocknumber() public { - assertEq(zeroBlocknumber().toInt(), 0); + assertEq(BlocknumberLib.zero().toInt(), 0); } function test_blockBlocknumber() public { uint256 bn = block.number; - assertEq(blockBlocknumber().toInt(), bn); + assertEq(BlocknumberLib.current().toInt(), bn); vm.warp(100); bn = block.number; - assertEq(blockBlocknumber().toInt(), bn); + assertEq(BlocknumberLib.current().toInt(), bn); } function test_op_gt() public {