CREATE2 callback validation; init code storage contracts

This commit is contained in:
tim
2025-11-13 16:41:52 -04:00
parent c2ac0e3624
commit 9273430f2a
28 changed files with 779 additions and 588 deletions

View File

@@ -18,7 +18,7 @@ contract PartyPoolSwapImpl is PartyPoolBase {
using LMSRStabilized for LMSRStabilized.State;
using SafeERC20 for IERC20;
constructor(NativeWrapper wrapper_) PartyPoolBase(wrapper_) {}
constructor(NativeWrapper wrapper_) {WRAPPER = wrapper_;}
bytes32 internal constant FLASH_CALLBACK_SUCCESS = keccak256("ERC3156FlashBorrower.onFlashLoan");
@@ -94,12 +94,14 @@ contract PartyPoolSwapImpl is PartyPoolBase {
function swapToLimit(
address payer,
bytes4 fundingSelector,
address receiver,
uint256 inputTokenIndex,
uint256 outputTokenIndex,
int128 limitPrice,
uint256 deadline,
bool unwrap,
bytes memory cbData,
uint256 swapFeePpm,
uint256 protocolFeePpm
) external payable native killable nonReentrant returns (uint256 amountInUsed, uint256 amountOut, uint256 inFee) {
@@ -109,18 +111,15 @@ contract PartyPoolSwapImpl is PartyPoolBase {
require(deadline == 0 || block.timestamp <= deadline, "swapToLimit: deadline exceeded");
// Read previous balances for affected assets
uint256 prevBalI = IERC20(_tokens[inputTokenIndex]).balanceOf(address(this));
uint256 prevBalJ = IERC20(_tokens[outputTokenIndex]).balanceOf(address(this));
uint256 prevBalJ = _cachedUintBalances[outputTokenIndex];
// Compute amounts using the same path as views
(uint256 totalTransferAmount, uint256 amountOutUint, int128 amountInInternalMax, int128 amountOutInternal, uint256 amountInUsedUint, uint256 feeUint) =
_quoteSwapToLimit(inputTokenIndex, outputTokenIndex, limitPrice, swapFeePpm);
// Transfer the exact amount needed from payer and require exact receipt (revert on fee-on-transfer)
// Transfer the exact amount needed from payer
IERC20 tokenIn = _tokens[inputTokenIndex];
_receiveTokenFrom(payer, tokenIn, totalTransferAmount);
uint256 balIAfter = tokenIn.balanceOf(address(this));
require(balIAfter == prevBalI + totalTransferAmount, "swapToLimit: non-standard tokenIn");
_receiveTokenFrom(payer, fundingSelector, inputTokenIndex, tokenIn, totalTransferAmount, limitPrice, cbData);
// Transfer output to receiver and verify exact decrease
IERC20 tokenOut = _tokens[outputTokenIndex];
@@ -137,10 +136,6 @@ contract PartyPoolSwapImpl is PartyPoolBase {
}
}
// Update caches to effective balances (inline _recordCachedBalance)
require(balIAfter >= _protocolFeesOwed[inputTokenIndex], "balance < protocol owed");
_cachedUintBalances[inputTokenIndex] = balIAfter - _protocolFeesOwed[inputTokenIndex];
require(balJAfter >= _protocolFeesOwed[outputTokenIndex], "balance < protocol owed");
_cachedUintBalances[outputTokenIndex] = balJAfter - _protocolFeesOwed[outputTokenIndex];