-
Notifications
You must be signed in to change notification settings - Fork 505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rip Out Vanilla #138
Merged
saucepoint
merged 7 commits into
sauce/posm-batch-execute-transient
from
sauce/posm-batch-execute-transient-rip-vanilla
Jul 1, 2024
Merged
Rip Out Vanilla #138
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
cb13e34
rip out vanilla and benchmark
saucepoint 6db1674
fix gas benchmark
saucepoint 4224c5b
check posm is the locker before allowing access to external functions
saucepoint 2637b6e
restore execute tests
saucepoint c87b0ad
posm takes as 6909; remove legacy deadcode
saucepoint 9f472a2
restore tests
saucepoint b92abcc
move helpers to the same file
saucepoint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
300126 | ||
299532 |
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/autocompound_exactUnclaimedFees_exactCustodiedFees.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
239588 | ||
238996 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
320665 | ||
320071 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
215187 | ||
214591 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
215199 | ||
214603 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
195029 | ||
194748 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
195041 | ||
194760 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
512049 | ||
513700 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,8 +38,9 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit | |
// maps the ERC721 tokenId to the keys that uniquely identify a liquidity position (owner, range) | ||
mapping(uint256 tokenId => TokenPosition position) public tokenPositions; | ||
|
||
// TODO: TSTORE this jawn | ||
// TODO: TSTORE these jawns | ||
address internal msgSender; | ||
bool internal unlockedByThis; | ||
|
||
// TODO: Context is inherited through ERC721 and will be not useful to use _msgSender() which will be address(this) with our current mutlicall. | ||
function _msgSenderInternal() internal override returns (address) { | ||
|
@@ -51,35 +52,34 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit | |
ERC721Permit("Uniswap V4 Positions NFT-V1", "UNI-V4-POS", "1") | ||
{} | ||
|
||
function unlockAndExecute(bytes[] memory data, Currency[] memory currencies) public returns (bytes memory) { | ||
function unlockAndExecute(bytes[] memory data, Currency[] memory currencies) public returns (int128[] memory) { | ||
msgSender = msg.sender; | ||
return manager.unlock(abi.encode(data, currencies)); | ||
unlockedByThis = true; | ||
return abi.decode(manager.unlock(abi.encode(data, currencies)), (int128[])); | ||
} | ||
|
||
function _unlockCallback(bytes calldata payload) internal override returns (bytes memory) { | ||
(bytes[] memory data, Currency[] memory currencies) = abi.decode(payload, (bytes[], Currency[])); | ||
|
||
bool success; | ||
bytes memory returnData; | ||
|
||
for (uint256 i; i < data.length; i++) { | ||
// TODO: bubble up the return | ||
(success, returnData) = address(this).call(data[i]); | ||
(success,) = address(this).call(data[i]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rlly wish we could just parse selector and internally call.. now that I wanna add this modifer :( |
||
if (!success) revert("EXECUTE_FAILED"); | ||
} | ||
|
||
// close the deltas | ||
int128[] memory returnData = new int128[](currencies.length); | ||
for (uint256 i; i < currencies.length; i++) { | ||
currencies[i].close(manager, msgSender); | ||
returnData[i] = currencies[i].close(manager, msgSender); | ||
currencies[i].close(manager, address(this)); | ||
} | ||
|
||
// Should just be returning the netted amount that was settled on behalf of the caller (msgSender) | ||
// And any recipient deltas settled earlier. | ||
|
||
// TODO: @sara handle the return | ||
// vanilla: return int128[2] | ||
// batch: return int128[data.length] | ||
return returnData; | ||
// TODO: any recipient deltas settled earlier. | ||
// @comment sauce: i dont think we can return recipient deltas since we cant parse the payload | ||
return abi.encode(returnData); | ||
} | ||
|
||
// NOTE: more gas efficient as LiquidityAmounts is used offchain | ||
|
@@ -90,26 +90,13 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit | |
uint256 deadline, | ||
address owner, | ||
bytes calldata hookData | ||
) public payable returns (BalanceDelta delta) { | ||
// TODO: optimization, read/write manager.isUnlocked to avoid repeated external calls for batched execution | ||
if (manager.isUnlocked()) { | ||
saucepoint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_increaseLiquidity(owner, range, liquidity, hookData); | ||
|
||
// mint receipt token | ||
uint256 tokenId; | ||
_mint(owner, (tokenId = nextTokenId++)); | ||
tokenPositions[tokenId] = TokenPosition({owner: owner, range: range}); | ||
} else { | ||
msgSender = msg.sender; | ||
bytes[] memory data = new bytes[](1); | ||
data[0] = abi.encodeWithSelector(this.mint.selector, range, liquidity, deadline, owner, hookData); | ||
|
||
Currency[] memory currencies = new Currency[](2); | ||
currencies[0] = range.poolKey.currency0; | ||
currencies[1] = range.poolKey.currency1; | ||
bytes memory result = unlockAndExecute(data, currencies); | ||
delta = abi.decode(result, (BalanceDelta)); | ||
} | ||
) external payable onlyIfUnlocked { | ||
_increaseLiquidity(owner, range, liquidity, hookData); | ||
|
||
// mint receipt token | ||
uint256 tokenId; | ||
_mint(owner, (tokenId = nextTokenId++)); | ||
tokenPositions[tokenId] = TokenPosition({owner: owner, range: range}); | ||
} | ||
|
||
// NOTE: more expensive since LiquidityAmounts is used onchain | ||
|
@@ -135,43 +122,21 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit | |
function increaseLiquidity(uint256 tokenId, uint256 liquidity, bytes calldata hookData, bool claims) | ||
external | ||
isAuthorizedForToken(tokenId) | ||
returns (BalanceDelta delta) | ||
onlyIfUnlocked | ||
{ | ||
TokenPosition memory tokenPos = tokenPositions[tokenId]; | ||
|
||
if (manager.isUnlocked()) { | ||
_increaseLiquidity(tokenPos.owner, tokenPos.range, liquidity, hookData); | ||
} else { | ||
bytes[] memory data = new bytes[](1); | ||
data[0] = abi.encodeWithSelector(this.increaseLiquidity.selector, tokenId, liquidity, hookData, claims); | ||
|
||
Currency[] memory currencies = new Currency[](2); | ||
currencies[0] = tokenPos.range.poolKey.currency0; | ||
currencies[1] = tokenPos.range.poolKey.currency1; | ||
bytes memory result = unlockAndExecute(data, currencies); | ||
delta = abi.decode(result, (BalanceDelta)); | ||
} | ||
_increaseLiquidity(tokenPos.owner, tokenPos.range, liquidity, hookData); | ||
} | ||
|
||
function decreaseLiquidity(uint256 tokenId, uint256 liquidity, bytes calldata hookData, bool claims) | ||
public | ||
external | ||
isAuthorizedForToken(tokenId) | ||
returns (BalanceDelta delta) | ||
onlyIfUnlocked | ||
{ | ||
TokenPosition memory tokenPos = tokenPositions[tokenId]; | ||
|
||
if (manager.isUnlocked()) { | ||
_decreaseLiquidity(tokenPos.owner, tokenPos.range, liquidity, hookData); | ||
} else { | ||
bytes[] memory data = new bytes[](1); | ||
data[0] = abi.encodeWithSelector(this.decreaseLiquidity.selector, tokenId, liquidity, hookData, claims); | ||
|
||
Currency[] memory currencies = new Currency[](2); | ||
currencies[0] = tokenPos.range.poolKey.currency0; | ||
currencies[1] = tokenPos.range.poolKey.currency1; | ||
bytes memory result = unlockAndExecute(data, currencies); | ||
delta = abi.decode(result, (BalanceDelta)); | ||
} | ||
_decreaseLiquidity(tokenPos.owner, tokenPos.range, liquidity, hookData); | ||
} | ||
|
||
// TODO return type? | ||
|
@@ -188,22 +153,12 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit | |
|
||
// TODO: in v3, we can partially collect fees, but what was the usecase here? | ||
function collect(uint256 tokenId, address recipient, bytes calldata hookData, bool claims) | ||
public | ||
returns (BalanceDelta delta) | ||
external | ||
onlyIfUnlocked | ||
{ | ||
TokenPosition memory tokenPos = tokenPositions[tokenId]; | ||
if (manager.isUnlocked()) { | ||
_collect(recipient, tokenPos.range, hookData); | ||
} else { | ||
bytes[] memory data = new bytes[](1); | ||
data[0] = abi.encodeWithSelector(this.collect.selector, tokenId, recipient, hookData, claims); | ||
|
||
Currency[] memory currencies = new Currency[](2); | ||
currencies[0] = tokenPos.range.poolKey.currency0; | ||
currencies[1] = tokenPos.range.poolKey.currency1; | ||
bytes memory result = unlockAndExecute(data, currencies); | ||
delta = abi.decode(result, (BalanceDelta)); | ||
} | ||
|
||
_collect(recipient, tokenPos.owner, tokenPos.range, hookData); | ||
} | ||
|
||
function feesOwed(uint256 tokenId) external view returns (uint256 token0Owed, uint256 token1Owed) { | ||
|
@@ -234,4 +189,9 @@ contract NonfungiblePositionManager is INonfungiblePositionManager, BaseLiquidit | |
require(msg.sender == address(this) || _isApprovedOrOwner(msg.sender, tokenId), "Not approved"); | ||
_; | ||
} | ||
|
||
modifier onlyIfUnlocked() { | ||
if (!unlockedByThis) revert MustBeUnlockedByThisContract(); | ||
_; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lol