Skip to content

Commit

Permalink
rename BlocknumberLib.currentBlocknumber() to current()
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaszimmermann committed Sep 8, 2024
1 parent 80c610e commit 33aca5c
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion contracts/instance/base/BalanceStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ contract BalanceStore {

//--- internal/private functions ----------------------------------------//
function _setLastUpdatedIn(NftId targetNftId) internal {
_lastUpdatedIn[targetNftId] = BlocknumberLib.currentBlocknumber();
_lastUpdatedIn[targetNftId] = BlocknumberLib.current();
}
}
2 changes: 1 addition & 1 deletion contracts/shared/IKeyValueStore.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
6 changes: 3 additions & 3 deletions contracts/shared/KeyValueStore.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -38,7 +38,7 @@ abstract contract KeyValueStore is
revert ErrorKeyValueStoreNoLifecycle(objectType);
}

Blocknumber blocknumber = blockBlocknumber();
Blocknumber blocknumber = BlocknumberLib.current();
StateId initialState = getInitialState(objectType);

// set metadata
Expand Down Expand Up @@ -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) {
Expand Down
38 changes: 19 additions & 19 deletions contracts/staking/StakingStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ contract StakingStore is
}

info.stakingRate = UFixedLib.zero();
info.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
info.lastUpdatedIn = BlocknumberLib.current();
}


Expand Down Expand Up @@ -146,7 +146,7 @@ contract StakingStore is

// update values
info.stakingRate = stakingRate;
info.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
info.lastUpdatedIn = BlocknumberLib.current();
}

//--- target management -------------------------------------------------//
Expand Down Expand Up @@ -236,7 +236,7 @@ contract StakingStore is
// checks
targetInfo = _getAndVerifyTarget(targetNftId);
lastUpdatedIn = targetInfo.lastUpdatedIn;
targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
targetInfo.lastUpdatedIn = BlocknumberLib.current();
}


Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -325,7 +325,7 @@ contract StakingStore is

// effects
targetInfo.reserveAmount = targetInfo.reserveAmount + dipAmount;
targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
targetInfo.lastUpdatedIn = BlocknumberLib.current();
newReserveBalance = targetInfo.reserveAmount;
}

Expand All @@ -351,7 +351,7 @@ contract StakingStore is

// effects
targetInfo.reserveAmount = targetInfo.reserveAmount - dipAmount;
targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
targetInfo.lastUpdatedIn = BlocknumberLib.current();
newReserveBalance = targetInfo.reserveAmount;
}

Expand All @@ -372,7 +372,7 @@ contract StakingStore is

// effects
tvlInfo.tvlAmount = tvlInfo.tvlAmount + amount;
tvlInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
tvlInfo.lastUpdatedIn = BlocknumberLib.current();
newBalance = tvlInfo.tvlAmount;
}

Expand All @@ -391,7 +391,7 @@ contract StakingStore is

// effects
tvlInfo.tvlAmount = tvlInfo.tvlAmount - amount;
tvlInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
tvlInfo.lastUpdatedIn = BlocknumberLib.current();
newBalance = tvlInfo.tvlAmount;
}

Expand Down Expand Up @@ -422,15 +422,15 @@ contract StakingStore is
// effects
// update target
targetInfo.stakedAmount = stakedAmount;
targetInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
targetInfo.lastUpdatedIn = BlocknumberLib.current();

// update stake
stakeInfo.targetNftId = targetNftId;
stakeInfo.stakedAmount = stakedAmount;
stakeInfo.rewardAmount = AmountLib.zero();
stakeInfo.lockedUntil = lockedUntil;
stakeInfo.lastUpdateAt = TimestampLib.current();
stakeInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
stakeInfo.lastUpdatedIn = BlocknumberLib.current();
}


Expand All @@ -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()) {
Expand Down Expand Up @@ -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();
}


Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -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();
}


Expand All @@ -692,7 +692,7 @@ contract StakingStore is
lastUpdatedIn = tvlInfo.lastUpdatedIn;

tvlInfo.tvlAmount = newTvlAmount;
tvlInfo.lastUpdatedIn = BlocknumberLib.currentBlocknumber();
tvlInfo.lastUpdatedIn = BlocknumberLib.current();
}


Expand Down
26 changes: 14 additions & 12 deletions contracts/type/Blocknumber.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions contracts/type/Timestamp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 3 additions & 3 deletions test/staking/TvlCalculation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions test/type/Blocknumber.t.sol
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 {
Expand Down

0 comments on commit 33aca5c

Please sign in to comment.