diff --git a/.github/workflows/olympix.yaml b/.github/workflows/olympix.yaml new file mode 100644 index 00000000..cd13b3e9 --- /dev/null +++ b/.github/workflows/olympix.yaml @@ -0,0 +1,19 @@ +name: Integrated Security Workflow +on: + pull_request: + branches: [main, master, staging, dev, feat/**, fix/**] + push: + branches: [main, master, staging, dev] +jobs: + security: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Run Olympix Integrated Security + uses: olympix/integrated-security@main + env: + OLYMPIX_API_TOKEN: ${{ secrets.OLYMPIX_API_TOKEN }} + - name: Upload result to GitHub Code Scanning + uses: github/codeql-action/upload-sarif@v3 + with: + sarif_file: olympix.sarif \ No newline at end of file diff --git a/docs/autogen/src/SUMMARY.md b/docs/autogen/src/SUMMARY.md index b91a2ea6..196ee8d6 100644 --- a/docs/autogen/src/SUMMARY.md +++ b/docs/autogen/src/SUMMARY.md @@ -29,14 +29,14 @@ - [FixedPoint96](src/libraries/FixedPoint96.sol/library.FixedPoint96.md) - [ValueX7](src/libraries/MPSLib.sol/type.ValueX7.md) - [MPSLib](src/libraries/MPSLib.sol/library.MPSLib.md) + - [sub](src/libraries/MPSLib.sol/function.sub.md) + - [add](src/libraries/MPSLib.sol/function.add.md) + - [gte](src/libraries/MPSLib.sol/function.gte.md) - [eq](src/libraries/MPSLib.sol/function.eq.md) - - [divUint256](src/libraries/MPSLib.sol/function.divUint256.md) - [mulUint256](src/libraries/MPSLib.sol/function.mulUint256.md) - - [gte](src/libraries/MPSLib.sol/function.gte.md) + - [divUint256](src/libraries/MPSLib.sol/function.divUint256.md) - [gt](src/libraries/MPSLib.sol/function.gt.md) - - [add](src/libraries/MPSLib.sol/function.add.md) - [fullMulDiv](src/libraries/MPSLib.sol/function.fullMulDiv.md) - - [sub](src/libraries/MPSLib.sol/function.sub.md) - [ValidationHookLib](src/libraries/ValidationHookLib.sol/library.ValidationHookLib.md) - [Auction](src/Auction.sol/contract.Auction.md) - [AuctionFactory](src/AuctionFactory.sol/contract.AuctionFactory.md) diff --git a/docs/autogen/src/src/Auction.sol/contract.Auction.md b/docs/autogen/src/src/Auction.sol/contract.Auction.md index bf9b0c92..58d04207 100644 --- a/docs/autogen/src/src/Auction.sol/contract.Auction.md +++ b/docs/autogen/src/src/Auction.sol/contract.Auction.md @@ -1,5 +1,5 @@ # Auction -[Git Source](https://github.com/Uniswap/twap-auction/blob/f80ba18b60de4b770005741879dfdddb0bfb58e3/src/Auction.sol) +[Git Source](https://github.com/Uniswap/twap-auction/blob/97b9f50fc290e1d145d29832b96438e6ecfe03de/src/Auction.sol) **Inherits:** [BidStorage](/src/BidStorage.sol/abstract.BidStorage.md), [CheckpointStorage](/src/CheckpointStorage.sol/abstract.CheckpointStorage.md), [AuctionStepStorage](/src/AuctionStepStorage.sol/abstract.AuctionStepStorage.md), [TickStorage](/src/TickStorage.sol/abstract.TickStorage.md), [PermitSingleForwarder](/src/PermitSingleForwarder.sol/abstract.PermitSingleForwarder.md), [TokenCurrencyStorage](/src/TokenCurrencyStorage.sol/abstract.TokenCurrencyStorage.md), [IAuction](/src/interfaces/IAuction.sol/interface.IAuction.md) @@ -395,3 +395,26 @@ The address of the validation hook for the auction function validationHook() external view override(IAuction) returns (IValidationHook); ``` +### getBidRequiredCurrencyAmount + +Getters + + +```solidity +function getBidRequiredCurrencyAmount(bool exactIn, uint256 amount, uint256 maxPrice) external pure returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exactIn`|`bool`|Whether the bid is exact in| +|`amount`|`uint256`|The amount of the bid| +|`maxPrice`|`uint256`|The max price of the bid| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The required currency amount for a bid| + + diff --git a/docs/autogen/src/src/BidStorage.sol/abstract.BidStorage.md b/docs/autogen/src/src/BidStorage.sol/abstract.BidStorage.md index e0228914..dc768467 100644 --- a/docs/autogen/src/src/BidStorage.sol/abstract.BidStorage.md +++ b/docs/autogen/src/src/BidStorage.sol/abstract.BidStorage.md @@ -1,5 +1,5 @@ # BidStorage -[Git Source](https://github.com/Uniswap/twap-auction/blob/f80ba18b60de4b770005741879dfdddb0bfb58e3/src/BidStorage.sol) +[Git Source](https://github.com/Uniswap/twap-auction/blob/97b9f50fc290e1d145d29832b96438e6ecfe03de/src/BidStorage.sol) ## State Variables @@ -102,3 +102,24 @@ function _deleteBid(uint256 bidId) internal; |`bidId`|`uint256`|The id of the bid to delete| +### getBid + +Get a bid from storage + + +```solidity +function getBid(uint256 bidId) external view returns (Bid memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`bidId`|`uint256`|The id of the bid to get| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`Bid`|bid The bid| + + diff --git a/docs/autogen/src/src/CheckpointStorage.sol/abstract.CheckpointStorage.md b/docs/autogen/src/src/CheckpointStorage.sol/abstract.CheckpointStorage.md index 4ca40002..cf300909 100644 --- a/docs/autogen/src/src/CheckpointStorage.sol/abstract.CheckpointStorage.md +++ b/docs/autogen/src/src/CheckpointStorage.sol/abstract.CheckpointStorage.md @@ -1,5 +1,5 @@ # CheckpointStorage -[Git Source](https://github.com/Uniswap/twap-auction/blob/f80ba18b60de4b770005741879dfdddb0bfb58e3/src/CheckpointStorage.sol) +[Git Source](https://github.com/Uniswap/twap-auction/blob/97b9f50fc290e1d145d29832b96438e6ecfe03de/src/CheckpointStorage.sol) **Inherits:** [ICheckpointStorage](/src/interfaces/ICheckpointStorage.sol/interface.ICheckpointStorage.md) @@ -38,6 +38,8 @@ uint64 public lastCheckpointedBlock; Get the latest checkpoint at the last checkpointed block +*This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand.* + ```solidity function latestCheckpoint() public view returns (Checkpoint memory); @@ -47,6 +49,8 @@ function latestCheckpoint() public view returns (Checkpoint memory); Get the clearing price at the last checkpointed block +*This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand.* + ```solidity function clearingPrice() public view returns (uint256); @@ -56,13 +60,36 @@ function clearingPrice() public view returns (uint256); Get the currency raised at the last checkpointed block -*This may be less than the balance of this contract as tokens are sold at different prices* +*This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand.* ```solidity function currencyRaised() public view returns (uint256); ``` +### getCheckpoint + +Get a checkpoint at a block number + +*The returned checkpoint may not exist if the block was never checkpointed* + + +```solidity +function getCheckpoint(uint64 blockNumber) external view returns (Checkpoint memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`blockNumber`|`uint64`|The block number of the checkpoint to get| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`Checkpoint`|checkpoint The checkpoint at the block number| + + ### _getCheckpoint Get a checkpoint from storage diff --git a/docs/autogen/src/src/TickStorage.sol/abstract.TickStorage.md b/docs/autogen/src/src/TickStorage.sol/abstract.TickStorage.md index 470f4c31..4890b5fe 100644 --- a/docs/autogen/src/src/TickStorage.sol/abstract.TickStorage.md +++ b/docs/autogen/src/src/TickStorage.sol/abstract.TickStorage.md @@ -1,5 +1,5 @@ # TickStorage -[Git Source](https://github.com/Uniswap/twap-auction/blob/f80ba18b60de4b770005741879dfdddb0bfb58e3/src/TickStorage.sol) +[Git Source](https://github.com/Uniswap/twap-auction/blob/97b9f50fc290e1d145d29832b96438e6ecfe03de/src/TickStorage.sol) **Inherits:** [ITickStorage](/src/interfaces/ITickStorage.sol/interface.ITickStorage.md) @@ -61,7 +61,7 @@ uint256 public constant MAX_TICK_PRICE = type(uint256).max; constructor(uint256 _tickSpacing, uint256 _floorPrice); ``` -### getTick +### _getTick Get a tick at a price @@ -69,7 +69,7 @@ Get a tick at a price ```solidity -function getTick(uint256 price) public view returns (Tick memory); +function _getTick(uint256 price) public view returns (Tick memory); ``` **Parameters** @@ -148,3 +148,20 @@ Get the tick spacing enforced for bid prices function tickSpacing() external view override(ITickStorage) returns (uint256); ``` +### getTick + +Get a tick at a price + +*The returned tick is not guaranteed to be initialized* + + +```solidity +function getTick(uint256 price) external view returns (Tick memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`price`|`uint256`|The price of the tick| + + diff --git a/docs/autogen/src/src/interfaces/IAuction.sol/interface.IAuction.md b/docs/autogen/src/src/interfaces/IAuction.sol/interface.IAuction.md index 24343767..7f49dd6a 100644 --- a/docs/autogen/src/src/interfaces/IAuction.sol/interface.IAuction.md +++ b/docs/autogen/src/src/interfaces/IAuction.sol/interface.IAuction.md @@ -1,5 +1,5 @@ # IAuction -[Git Source](https://github.com/Uniswap/twap-auction/blob/f80ba18b60de4b770005741879dfdddb0bfb58e3/src/interfaces/IAuction.sol) +[Git Source](https://github.com/Uniswap/twap-auction/blob/97b9f50fc290e1d145d29832b96438e6ecfe03de/src/interfaces/IAuction.sol) **Inherits:** [IDistributionContract](/src/interfaces/external/IDistributionContract.sol/interface.IDistributionContract.md), [ICheckpointStorage](/src/interfaces/ICheckpointStorage.sol/interface.ICheckpointStorage.md), [ITickStorage](/src/interfaces/ITickStorage.sol/interface.ITickStorage.md), [IAuctionStepStorage](/src/interfaces/IAuctionStepStorage.sol/interface.IAuctionStepStorage.md), [ITokenCurrencyStorage](/src/interfaces/ITokenCurrencyStorage.sol/interface.ITokenCurrencyStorage.md) @@ -159,6 +159,31 @@ Sweep any leftover tokens to the tokens recipient function sweepUnsoldTokens() external; ``` +### getBidRequiredCurrencyAmount + +Getters + +Get the required currency amount for a bid + + +```solidity +function getBidRequiredCurrencyAmount(bool exactIn, uint256 amount, uint256 maxPrice) external view returns (uint256); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`exactIn`|`bool`|Whether the bid is exact in| +|`amount`|`uint256`|The amount of the bid| +|`maxPrice`|`uint256`|The max price of the bid| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`uint256`|The required currency amount for a bid| + + ## Events ### TokensReceived Emitted when the tokens are received diff --git a/docs/autogen/src/src/interfaces/ICheckpointStorage.sol/interface.ICheckpointStorage.md b/docs/autogen/src/src/interfaces/ICheckpointStorage.sol/interface.ICheckpointStorage.md index f10fd688..2a3d613c 100644 --- a/docs/autogen/src/src/interfaces/ICheckpointStorage.sol/interface.ICheckpointStorage.md +++ b/docs/autogen/src/src/interfaces/ICheckpointStorage.sol/interface.ICheckpointStorage.md @@ -1,5 +1,5 @@ # ICheckpointStorage -[Git Source](https://github.com/Uniswap/twap-auction/blob/f80ba18b60de4b770005741879dfdddb0bfb58e3/src/interfaces/ICheckpointStorage.sol) +[Git Source](https://github.com/Uniswap/twap-auction/blob/97b9f50fc290e1d145d29832b96438e6ecfe03de/src/interfaces/ICheckpointStorage.sol) ## Functions @@ -7,6 +7,8 @@ Get the latest checkpoint at the last checkpointed block +*This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand.* + ```solidity function latestCheckpoint() external view returns (Checkpoint memory); @@ -16,6 +18,8 @@ function latestCheckpoint() external view returns (Checkpoint memory); Get the clearing price at the last checkpointed block +*This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand.* + ```solidity function clearingPrice() external view returns (uint256); @@ -25,7 +29,9 @@ function clearingPrice() external view returns (uint256); Get the currency raised at the last checkpointed block -*This may be less than the balance of this contract as tokens are sold at different prices* +*This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand.* + +*This also may be less than the balance of this contract as tokens are sold at different prices.* ```solidity @@ -36,8 +42,33 @@ function currencyRaised() external view returns (uint256); Get the number of the last checkpointed block +*This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand.* + ```solidity function lastCheckpointedBlock() external view returns (uint64); ``` +### getCheckpoint + +Get a checkpoint at a block number + +*The returned checkpoint may not exist if the block was never checkpointed* + + +```solidity +function getCheckpoint(uint64 blockNumber) external view returns (Checkpoint memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`blockNumber`|`uint64`|The block number of the checkpoint to get| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`Checkpoint`|checkpoint The checkpoint at the block number| + + diff --git a/docs/autogen/src/src/interfaces/ITickStorage.sol/interface.ITickStorage.md b/docs/autogen/src/src/interfaces/ITickStorage.sol/interface.ITickStorage.md index 34335486..c98234d2 100644 --- a/docs/autogen/src/src/interfaces/ITickStorage.sol/interface.ITickStorage.md +++ b/docs/autogen/src/src/interfaces/ITickStorage.sol/interface.ITickStorage.md @@ -1,5 +1,5 @@ # ITickStorage -[Git Source](https://github.com/Uniswap/twap-auction/blob/67125c85f3326c7fe287a8da9446ecc07698d947/src/interfaces/ITickStorage.sol) +[Git Source](https://github.com/Uniswap/twap-auction/blob/97b9f50fc290e1d145d29832b96438e6ecfe03de/src/interfaces/ITickStorage.sol) Interface for the TickStorage contract @@ -34,6 +34,23 @@ Get the tick spacing enforced for bid prices function tickSpacing() external view returns (uint256); ``` +### getTick + +Get a tick at a price + +*The returned tick is not guaranteed to be initialized* + + +```solidity +function getTick(uint256 price) external view returns (Tick memory); +``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`price`|`uint256`|The price of the tick| + + ## Events ### TickInitialized Emitted when a tick is initialized diff --git a/docs/autogen/src/src/libraries/README.md b/docs/autogen/src/src/libraries/README.md index ba563b72..d788f4aa 100644 --- a/docs/autogen/src/src/libraries/README.md +++ b/docs/autogen/src/src/libraries/README.md @@ -14,12 +14,12 @@ - [FixedPoint96](FixedPoint96.sol/library.FixedPoint96.md) - [ValueX7](MPSLib.sol/type.ValueX7.md) - [MPSLib](MPSLib.sol/library.MPSLib.md) +- [sub](MPSLib.sol/function.sub.md) +- [add](MPSLib.sol/function.add.md) +- [gte](MPSLib.sol/function.gte.md) - [eq](MPSLib.sol/function.eq.md) -- [divUint256](MPSLib.sol/function.divUint256.md) - [mulUint256](MPSLib.sol/function.mulUint256.md) -- [gte](MPSLib.sol/function.gte.md) +- [divUint256](MPSLib.sol/function.divUint256.md) - [gt](MPSLib.sol/function.gt.md) -- [add](MPSLib.sol/function.add.md) - [fullMulDiv](MPSLib.sol/function.fullMulDiv.md) -- [sub](MPSLib.sol/function.sub.md) - [ValidationHookLib](ValidationHookLib.sol/library.ValidationHookLib.md) diff --git a/snapshots/AuctionTest.json b/snapshots/AuctionTest.json index 08ac5c0f..ac2b9bdc 100644 --- a/snapshots/AuctionTest.json +++ b/snapshots/AuctionTest.json @@ -1,13 +1,13 @@ { - "checkpoint_advanceToCurrentStep": "157988", - "checkpoint_noBids": "141549", - "checkpoint_zeroSupply": "145295", - "claimTokens": "83315", + "checkpoint_advanceToCurrentStep": "158000", + "checkpoint_noBids": "141561", + "checkpoint_zeroSupply": "145303", + "claimTokens": "83293", "exitBid": "90090", - "exitPartiallyFilledBid": "290600", - "submitBid": "161288", - "submitBid_recordStep_updateCheckpoint": "314320", - "submitBid_recordStep_updateCheckpoint_initializeTick": "314320", - "submitBid_updateCheckpoint": "299530", - "submitBid_withValidationHook": "318561" + "exitPartiallyFilledBid": "290602", + "submitBid": "161323", + "submitBid_recordStep_updateCheckpoint": "314367", + "submitBid_recordStep_updateCheckpoint_initializeTick": "314367", + "submitBid_updateCheckpoint": "299577", + "submitBid_withValidationHook": "318608" } \ No newline at end of file diff --git a/src/Auction.sol b/src/Auction.sol index 518fa6d5..b44f9c6c 100644 --- a/src/Auction.sol +++ b/src/Auction.sol @@ -221,7 +221,7 @@ contract Auction is // The clearing price can never be lower than the last checkpoint uint256 minimumClearingPrice = _checkpoint.clearingPrice; // The next price tick initialized with demand is the `nextActiveTickPrice` - Tick memory _nextActiveTick = getTick(nextActiveTickPrice); + Tick memory _nextActiveTick = _getTick(nextActiveTickPrice); // For a non-zero supply, iterate to find the tick where the demand at and above it is strictly less than the supply // Sets nextActiveTickPrice to MAX_TICK_PRICE if the highest tick in the book is reached @@ -236,7 +236,7 @@ contract Auction is // Advance to the next tick uint256 _nextTickPrice = _nextActiveTick.next; nextActiveTickPrice = _nextTickPrice; - _nextActiveTick = getTick(_nextTickPrice); + _nextActiveTick = _getTick(_nextTickPrice); } // Save state variables @@ -451,7 +451,7 @@ contract Auction is (uint256 partialTokensFilled, uint256 partialCurrencySpent) = _accountPartiallyFilledCheckpoints( upperCheckpoint.cumulativeSupplySoldToClearingPriceX7, bid.toDemand().resolve(bid.maxPrice), - getTick(bid.maxPrice).demand.resolve(bid.maxPrice), + _getTick(bid.maxPrice).demand.resolve(bid.maxPrice), bid.maxPrice ); tokensFilled += partialTokensFilled; @@ -509,4 +509,13 @@ contract Auction is function validationHook() external view override(IAuction) returns (IValidationHook) { return VALIDATION_HOOK; } + + /// @inheritdoc IAuction + function getBidRequiredCurrencyAmount(bool exactIn, uint256 amount, uint256 maxPrice) + external + pure + returns (uint256) + { + return BidLib.inputAmount(exactIn, amount, maxPrice); + } } diff --git a/src/BidStorage.sol b/src/BidStorage.sol index 3ec714ec..62806eed 100644 --- a/src/BidStorage.sol +++ b/src/BidStorage.sol @@ -56,4 +56,13 @@ abstract contract BidStorage { function _deleteBid(uint256 bidId) internal { delete bids[bidId]; } + + // Getters + + /// @notice Get a bid from storage + /// @param bidId The id of the bid to get + /// @return bid The bid + function getBid(uint256 bidId) external view returns (Bid memory) { + return _getBid(bidId); + } } diff --git a/src/CheckpointStorage.sol b/src/CheckpointStorage.sol index e889e31e..97128ead 100644 --- a/src/CheckpointStorage.sol +++ b/src/CheckpointStorage.sol @@ -44,6 +44,11 @@ abstract contract CheckpointStorage is ICheckpointStorage { return _getCheckpoint(lastCheckpointedBlock).getCurrencyRaised(); } + /// @inheritdoc ICheckpointStorage + function getCheckpoint(uint64 blockNumber) external view returns (Checkpoint memory) { + return _getCheckpoint(blockNumber); + } + /// @notice Get a checkpoint from storage function _getCheckpoint(uint64 blockNumber) internal view returns (Checkpoint memory) { return checkpoints[blockNumber]; diff --git a/src/TickStorage.sol b/src/TickStorage.sol index 1c00178c..2a2f0694 100644 --- a/src/TickStorage.sol +++ b/src/TickStorage.sol @@ -37,7 +37,7 @@ abstract contract TickStorage is ITickStorage { /// @notice Get a tick at a price /// @dev The returned tick is not guaranteed to be initialized /// @param price The price of the tick - function getTick(uint256 price) public view returns (Tick memory) { + function _getTick(uint256 price) public view returns (Tick memory) { return ticks[price]; } @@ -107,4 +107,9 @@ abstract contract TickStorage is ITickStorage { function tickSpacing() external view override(ITickStorage) returns (uint256) { return TICK_SPACING; } + + /// @inheritdoc ITickStorage + function getTick(uint256 price) external view returns (Tick memory) { + return _getTick(price); + } } diff --git a/src/interfaces/IAuction.sol b/src/interfaces/IAuction.sol index ff21e92c..8aed5850 100644 --- a/src/interfaces/IAuction.sol +++ b/src/interfaces/IAuction.sol @@ -158,4 +158,16 @@ interface IAuction is /// @notice Sweep any leftover tokens to the tokens recipient /// @dev This function can only be called after the auction has ended function sweepUnsoldTokens() external; + + /// Getters + + /// @notice Get the required currency amount for a bid + /// @param exactIn Whether the bid is exact in + /// @param amount The amount of the bid + /// @param maxPrice The max price of the bid + /// @return The required currency amount for a bid + function getBidRequiredCurrencyAmount(bool exactIn, uint256 amount, uint256 maxPrice) + external + view + returns (uint256); } diff --git a/src/interfaces/ICheckpointStorage.sol b/src/interfaces/ICheckpointStorage.sol index 55575fb6..2c97cd0b 100644 --- a/src/interfaces/ICheckpointStorage.sol +++ b/src/interfaces/ICheckpointStorage.sol @@ -5,15 +5,25 @@ import {Checkpoint} from '../libraries/CheckpointLib.sol'; interface ICheckpointStorage { /// @notice Get the latest checkpoint at the last checkpointed block + /// @dev This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand. function latestCheckpoint() external view returns (Checkpoint memory); /// @notice Get the clearing price at the last checkpointed block + /// @dev This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand. function clearingPrice() external view returns (uint256); /// @notice Get the currency raised at the last checkpointed block - /// @dev This may be less than the balance of this contract as tokens are sold at different prices + /// @dev This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand. + /// @dev This also may be less than the balance of this contract as tokens are sold at different prices. function currencyRaised() external view returns (uint256); /// @notice Get the number of the last checkpointed block + /// @dev This may be out of date and not reflect the latest state of the auction. As a best practice, always call `checkpoint()` beforehand. function lastCheckpointedBlock() external view returns (uint64); + + /// @notice Get a checkpoint at a block number + /// @dev The returned checkpoint may not exist if the block was never checkpointed + /// @param blockNumber The block number of the checkpoint to get + /// @return checkpoint The checkpoint at the block number + function getCheckpoint(uint64 blockNumber) external view returns (Checkpoint memory); } diff --git a/src/interfaces/ITickStorage.sol b/src/interfaces/ITickStorage.sol index 834a6c84..36424ab3 100644 --- a/src/interfaces/ITickStorage.sol +++ b/src/interfaces/ITickStorage.sol @@ -30,4 +30,9 @@ interface ITickStorage { /// @notice Get the tick spacing enforced for bid prices function tickSpacing() external view returns (uint256); + + /// @notice Get a tick at a price + /// @dev The returned tick is not guaranteed to be initialized + /// @param price The price of the tick + function getTick(uint256 price) external view returns (Tick memory); } diff --git a/test/utils/MockCheckpointStorage.sol b/test/utils/MockCheckpointStorage.sol index a202d00f..c52e6db9 100644 --- a/test/utils/MockCheckpointStorage.sol +++ b/test/utils/MockCheckpointStorage.sol @@ -7,10 +7,6 @@ import {Checkpoint} from '../../src/libraries/CheckpointLib.sol'; import {ValueX7} from '../../src/libraries/MPSLib.sol'; contract MockCheckpointStorage is CheckpointStorage { - function getCheckpoint(uint64 blockNumber) external view returns (Checkpoint memory) { - return _getCheckpoint(blockNumber); - } - function insertCheckpoint(Checkpoint memory checkpoint, uint64 blockNumber) external { _insertCheckpoint(checkpoint, blockNumber); }