Skip to content

Commit 49c32de

Browse files
committed
wip: compiles
1 parent 4fa463e commit 49c32de

File tree

9 files changed

+33
-53
lines changed

9 files changed

+33
-53
lines changed

foundry.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[profile.default]
2-
solc = "0.8.23"
2+
solc = "0.8.28"
33
#via_ir = true
4+
evm_version = "cancun"
45
bytecode_hash = "ipfs"
56
optimizer_runs = 1_000_000
67
gas_limit = "18446744073709551615"

src/GenericFactory.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ pragma solidity ^0.8.0;
33

44
import { Math } from "@openzeppelin/utils/math/Math.sol";
55
import { Address } from "@openzeppelin/utils/Address.sol";
6+
import { Ownable } from "@openzeppelin/access/Ownable.sol";
67
import { SSTORE2 } from "solady/utils/SSTORE2.sol";
7-
import { Owned } from "solmate/auth/Owned.sol";
88

99
import { Bytes32Lib } from "src/libraries/Bytes32.sol";
1010

@@ -13,12 +13,12 @@ import { StableMintBurn } from "src/curve/stable/StableMintBurn.sol";
1313

1414
uint256 constant MAX_SSTORE_SIZE = 0x6000 - 1;
1515

16-
contract GenericFactory is IGenericFactory, Owned {
16+
contract GenericFactory is IGenericFactory, Ownable {
1717
using Bytes32Lib for address;
1818

1919
StableMintBurn public immutable stableMintBurn;
2020

21-
constructor() Owned(msg.sender) {
21+
constructor() Ownable (msg.sender) {
2222
stableMintBurn = new StableMintBurn{ salt: bytes32(0) }();
2323
}
2424

@@ -185,6 +185,6 @@ contract GenericFactory is IGenericFactory, Owned {
185185
onlyOwner
186186
returns (bytes memory)
187187
{
188-
return Address.functionCallWithValue(aTarget, aCalldata, aValue, "FACTORY: RAW_CALL_REVERTED");
188+
return Address.functionCallWithValue(aTarget, aCalldata, aValue);
189189
}
190190
}

src/ReservoirDeployer.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,6 @@ contract ReservoirDeployer {
150150
onlyOwner
151151
returns (bytes memory)
152152
{
153-
return Address.functionCallWithValue(aTarget, aCalldata, aValue, "DEPLOYER: RAW_CALL_REVERTED");
153+
return Address.functionCallWithValue(aTarget, aCalldata, aValue);
154154
}
155155
}

src/ReservoirPair.sol

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
pragma solidity ^0.8.0;
33

44
import { SafeCast } from "@openzeppelin/utils/math/SafeCast.sol";
5+
import { ReentrancyGuardTransient } from "@openzeppelin/utils/ReentrancyGuardTransient.sol";
56
import { FixedPointMathLib } from "solady/utils/FixedPointMathLib.sol";
67
import { SafeTransferLib } from "solady/utils/SafeTransferLib.sol";
78

@@ -19,7 +20,7 @@ import { Observation } from "src/structs/Observation.sol";
1920
import { Slot0 } from "src/structs/Slot0.sol";
2021
import { ReservoirERC20 } from "src/ReservoirERC20.sol";
2122

22-
abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 {
23+
abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20, ReentrancyGuardTransient {
2324
using FactoryStoreLib for IGenericFactory;
2425
using Bytes32Lib for bytes32;
2526
using SafeCast for uint256;
@@ -96,48 +97,23 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 {
9697
9798
//////////////////////////////////////////////////////////////////////////*/
9899

99-
Slot0 internal _slot0 = Slot0({ reserve0: 0, reserve1: 0, packedTimestamp: 0, index: Buffer.SIZE - 1 });
100+
Slot0 internal _slot0 = Slot0({ reserve0: 0, reserve1: 0, timestamp: 0, index: Buffer.SIZE - 1 });
100101

101-
function _currentTime() internal view returns (uint32) {
102-
return uint32(block.timestamp & 0x7FFFFFFF);
103-
}
104-
105-
function _splitSlot0Timestamp(uint32 aPackedTimestamp) internal pure returns (uint32 rTimestamp, bool rLocked) {
106-
rLocked = aPackedTimestamp >> 31 == 1;
107-
rTimestamp = aPackedTimestamp & 0x7FFFFFFF;
108-
}
109-
110-
/// @notice Writes the packed timestamp & re-entrancy guard into slot0.
111-
/// @dev The timestamp argument must not exceed 2**31.
112-
function _writeSlot0Timestamp(Slot0 storage sSlot0, uint32 aTimestamp, bool aLocked) internal {
113-
uint32 lLocked = aLocked ? uint32(1 << 31) : uint32(0);
114-
sSlot0.packedTimestamp = aTimestamp | lLocked;
115-
}
116-
117-
function _lockAndLoad()
102+
function _load()
118103
internal
119104
returns (Slot0 storage, uint104 rReserve0, uint104 rReserve1, uint32 rBlockTimestampLast, uint16 rIndex)
120105
{
121106
Slot0 storage sSlot0 = _slot0;
122107

123108
// Load slot0 values.
124-
bool lLock;
125109
rReserve0 = sSlot0.reserve0;
126110
rReserve1 = sSlot0.reserve1;
127-
(rBlockTimestampLast, lLock) = _splitSlot0Timestamp(sSlot0.packedTimestamp);
111+
rBlockTimestampLast = sSlot0.timestamp;
128112
rIndex = sSlot0.index;
129113

130-
// Acquire reentrancy lock.
131-
require(!lLock, "REENTRANCY");
132-
_writeSlot0Timestamp(sSlot0, rBlockTimestampLast, true);
133-
134114
return (sSlot0, rReserve0, rReserve1, rBlockTimestampLast, rIndex);
135115
}
136116

137-
function _unlock(Slot0 storage sSlot0, uint32 aBlockTimestampLast) internal {
138-
_writeSlot0Timestamp(sSlot0, aBlockTimestampLast, false);
139-
}
140-
141117
/// @notice Updates reserves with new balances.
142118
/// @notice On the first call per block, accumulate price oracle using previous instant prices and write the new instant prices.
143119
/// @dev The price is not updated on subsequent swaps as manipulating
@@ -153,7 +129,7 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 {
153129
require(aBalance0 <= type(uint104).max && aBalance1 <= type(uint104).max, "RP: OVERFLOW");
154130
require(aReserve0 <= type(uint104).max && aReserve1 <= type(uint104).max, "RP: OVERFLOW");
155131

156-
uint32 lBlockTimestamp = _currentTime();
132+
uint32 lBlockTimestamp = uint32(block.timestamp); // invalid after year 2106
157133
uint32 lTimeElapsed;
158134
unchecked {
159135
// underflow is desired
@@ -199,7 +175,7 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 {
199175
// update reserves to match latest balances
200176
sSlot0.reserve0 = uint104(aBalance0);
201177
sSlot0.reserve1 = uint104(aBalance1);
202-
_writeSlot0Timestamp(sSlot0, lBlockTimestamp, false);
178+
sSlot0.timestamp = lBlockTimestamp;
203179

204180
emit Sync(uint104(aBalance0), uint104(aBalance1));
205181
}
@@ -213,25 +189,26 @@ abstract contract ReservoirPair is IAssetManagedPair, ReservoirERC20 {
213189

214190
rReserve0 = lSlot0.reserve0;
215191
rReserve1 = lSlot0.reserve1;
216-
(rBlockTimestampLast,) = _splitSlot0Timestamp(lSlot0.packedTimestamp);
192+
rBlockTimestampLast = lSlot0.timestamp;
217193
rIndex = lSlot0.index;
218194
}
219195

220196
/// @notice Force reserves to match balances.
221-
function sync() external {
222-
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _lockAndLoad();
197+
function sync() external nonReentrant {
198+
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _load();
223199
(lReserve0, lReserve1) = _syncManaged(lReserve0, lReserve1);
224200

225201
_updateAndUnlock(sSlot0, _totalToken0(), _totalToken1(), lReserve0, lReserve1, lBlockTimestampLast);
226202
}
227203

228204
/// @notice Force balances to match reserves.
229-
function skim(address aTo) external {
230-
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _lockAndLoad();
205+
function skim(address aTo) external nonReentrant {
206+
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _load();
231207

232208
_checkedTransfer(token0(), aTo, _totalToken0() - lReserve0, lReserve0, lReserve1);
233209
_checkedTransfer(token1(), aTo, _totalToken1() - lReserve1, lReserve0, lReserve1);
234-
_unlock(sSlot0, lBlockTimestampLast);
210+
211+
// might need to do an update here
235212
}
236213

237214
/*//////////////////////////////////////////////////////////////////////////

src/asset-management/AaveManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ contract AaveManager is IAssetManager, Owned(msg.sender), ReentrancyGuard {
122122
onlyOwner
123123
returns (bytes memory)
124124
{
125-
return Address.functionCallWithValue(aTarget, aCalldata, aValue, "AM: RAW_CALL_REVERTED");
125+
return Address.functionCallWithValue(aTarget, aCalldata, aValue);
126126
}
127127
/*//////////////////////////////////////////////////////////////////////////
128128
HELPER FUNCTIONS

src/curve/constant-product/ConstantProductPair.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ contract ConstantProductPair is ReservoirPair {
9191
}
9292
}
9393

94-
function mint(address aTo) external override returns (uint256 rLiquidity) {
95-
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _lockAndLoad();
94+
function mint(address aTo) external override nonReentrant returns (uint256 rLiquidity) {
95+
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _load();
9696
(lReserve0, lReserve1) = _syncManaged(uint104(lReserve0), uint104(lReserve1)); // check asset-manager pnl
9797

9898
uint256 lBalance0 = _totalToken0();
@@ -122,9 +122,9 @@ contract ConstantProductPair is ReservoirPair {
122122
_managerCallback();
123123
}
124124

125-
function burn(address aTo) external override returns (uint256 rAmount0, uint256 rAmount1) {
125+
function burn(address aTo) external override nonReentrant returns (uint256 rAmount0, uint256 rAmount1) {
126126
// NB: Must sync management PNL before we load reserves.
127-
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _lockAndLoad();
127+
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _load();
128128
(lReserve0, lReserve1) = _syncManaged(uint104(lReserve0), uint104(lReserve1)); // check asset-manager pnl
129129

130130
uint256 liquidity = balanceOf[address(this)];
@@ -152,9 +152,10 @@ contract ConstantProductPair is ReservoirPair {
152152
function swap(int256 aAmount, bool aExactIn, address aTo, bytes calldata aData)
153153
external
154154
override
155+
nonReentrant
155156
returns (uint256 rAmountOut)
156157
{
157-
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _lockAndLoad();
158+
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _load();
158159
require(aAmount != 0, "CP: AMOUNT_ZERO");
159160
uint256 lAmountIn;
160161
IERC20 lTokenOut;

src/curve/stable/StableMintBurn.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ contract StableMintBurn is StablePair {
7878

7979
function mint(address aTo) external override returns (uint256 rLiquidity) {
8080
// NB: Must sync management PNL before we load reserves.
81-
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _lockAndLoad();
81+
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _load();
8282
(lReserve0, lReserve1) = _syncManaged(lReserve0, lReserve1);
8383

8484
uint256 lBalance0 = _totalToken0();
@@ -123,7 +123,7 @@ contract StableMintBurn is StablePair {
123123

124124
function burn(address aTo) external override returns (uint256 rAmount0, uint256 rAmount1) {
125125
// NB: Must sync management PNL before we load reserves.
126-
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _lockAndLoad();
126+
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _load();
127127
(lReserve0, lReserve1) = _syncManaged(lReserve0, lReserve1);
128128

129129
uint256 liquidity = balanceOf[address(this)];

src/curve/stable/StablePair.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ contract StablePair is ReservoirPair {
128128
external
129129
virtual
130130
override
131+
nonReentrant
131132
returns (uint256 rAmountOut)
132133
{
133-
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _lockAndLoad();
134+
(Slot0 storage sSlot0, uint256 lReserve0, uint256 lReserve1, uint32 lBlockTimestampLast,) = _load();
134135
require(aAmount != 0, "SP: AMOUNT_ZERO");
135136
uint256 lAmountIn;
136137
IERC20 lTokenOut;

src/structs/Slot0.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ pragma solidity ^0.8.0;
44
struct Slot0 {
55
uint104 reserve0;
66
uint104 reserve1;
7-
uint32 packedTimestamp;
7+
uint32 timestamp;
88
uint16 index;
99
}

0 commit comments

Comments
 (0)