-
Notifications
You must be signed in to change notification settings - Fork 229
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
V3 liquidity commands #355
Changes from 23 commits
60c4fc8
c70c9ff
568eafa
c30a295
7b63210
ec7e6e8
dee9fd3
89a56e4
44c77ee
0ff8024
83567fa
aab39ee
519ca80
4d0d406
af22cfe
ab21582
e65d3c5
caad744
77e6879
0d685e3
70e7e8a
21b7cd0
4726a9c
4aea013
c2eaed0
1aca629
31b15bf
bb39a36
40712fc
8296d4a
fd63875
567558c
b90b7bd
eae1ffa
d1f76f0
3349feb
0d37076
762158d
30d9e6d
62e5ff8
af02244
19a0a42
fde31eb
ee2dfc5
f4c4cf3
3575bb3
47d93fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.20; | ||
dianakocsis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
library TokenAuthorized { | ||
dianakocsis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
function _computeSlot(address spender, uint256 tokenId) internal pure returns (bytes32 hashSlot) { | ||
assembly ("memory-safe") { | ||
mstore(0, spender) | ||
mstore(32, tokenId) | ||
hashSlot := keccak256(0, 64) | ||
} | ||
} | ||
|
||
function setAuthorized(address spender, uint256 tokenId) internal { | ||
bytes32 hashSlot = _computeSlot(spender, tokenId); | ||
|
||
assembly { | ||
tstore(hashSlot, true) | ||
} | ||
} | ||
|
||
function getAuthorized(address spender, uint256 tokenId) internal view returns (bool authorized) { | ||
bytes32 hashSlot = _computeSlot(spender, tokenId); | ||
|
||
assembly { | ||
authorized := tload(hashSlot) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity ^0.8.24; | ||
|
||
import {MigratorImmutables} from '../modules/MigratorImmutables.sol'; | ||
import {INonfungiblePositionManager} from '@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol'; | ||
import {TokenAuthorized} from '../libraries/TokenAuthorized.sol'; | ||
|
||
abstract contract Migrator is MigratorImmutables { | ||
using TokenAuthorized for address; | ||
dianakocsis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function erc721Permit(address spender, uint256 tokenId, uint256 deadline, uint8 v, bytes32 r, bytes32 s) internal { | ||
V3_POSITION_MANGER.permit(spender, tokenId, deadline, v, r, s); | ||
dianakocsis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
function isValidV3Action(bytes4 selector) internal pure returns (bool) { | ||
return selector == INonfungiblePositionManager.decreaseLiquidity.selector | ||
|| selector == INonfungiblePositionManager.collect.selector | ||
|| selector == INonfungiblePositionManager.burn.selector; | ||
} | ||
|
||
function isAuthorizedForToken(address spender, uint256 tokenId) internal returns (bool authorized) { | ||
if (spender.getAuthorized(tokenId)) { | ||
return true; | ||
} else { | ||
address owner = V3_POSITION_MANGER.ownerOf(tokenId); | ||
dianakocsis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
authorized = spender == owner || V3_POSITION_MANGER.getApproved(tokenId) == spender | ||
|| V3_POSITION_MANGER.isApprovedForAll(owner, spender); | ||
if (authorized) { | ||
spender.setAuthorized(tokenId); | ||
} | ||
return authorized; | ||
dianakocsis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
pragma solidity ^0.8.24; | ||
|
||
import {INonfungiblePositionManager} from '@uniswap/v3-periphery/contracts/interfaces/INonfungiblePositionManager.sol'; | ||
|
||
struct MigratorParameters { | ||
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. any particular reason this is in a struct and is not just passed in as an address? when I read 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. because itll also include v4 position manager so this struct is just preemptively there i think.
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. Could change it but at this point it would be a bigger renaming overhaul of UR 😅 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. yeah i just followed the pattern from the others! and we'll have v4posm in there too 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. sg |
||
address v3PositionManager; | ||
} | ||
|
||
contract MigratorImmutables { | ||
/// @dev v3PositionManager address | ||
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. this should be
For example:
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. changed PaymentsImmutables too |
||
INonfungiblePositionManager internal immutable V3_POSITION_MANGER; | ||
|
||
constructor(MigratorParameters memory params) { | ||
V3_POSITION_MANGER = INonfungiblePositionManager(params.v3PositionManager); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// SPDX-License-Identifier: MIT | ||
// taken from openzeppelin@3.4.2 and updated the solidity version to fix remapping issues due to different location of the file | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import {IERC165} from '@openzeppelin/contracts-v4/utils/introspection/IERC165.sol'; | ||
|
||
/** | ||
* @dev Required interface of an ERC721 compliant contract. | ||
*/ | ||
interface IERC721 is IERC165 { | ||
/** | ||
* @dev Emitted when `tokenId` token is transferred from `from` to `to`. | ||
*/ | ||
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId); | ||
|
||
/** | ||
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token. | ||
*/ | ||
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId); | ||
|
||
/** | ||
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets. | ||
*/ | ||
event ApprovalForAll(address indexed owner, address indexed operator, bool approved); | ||
|
||
/** | ||
* @dev Returns the number of tokens in ``owner``'s account. | ||
*/ | ||
function balanceOf(address owner) external view returns (uint256 balance); | ||
|
||
/** | ||
* @dev Returns the owner of the `tokenId` token. | ||
* | ||
* Requirements: | ||
* | ||
* - `tokenId` must exist. | ||
*/ | ||
function ownerOf(uint256 tokenId) external view returns (address owner); | ||
|
||
/** | ||
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients | ||
* are aware of the ERC721 protocol to prevent tokens from being forever locked. | ||
* | ||
* Requirements: | ||
* | ||
* - `from` cannot be the zero address. | ||
* - `to` cannot be the zero address. | ||
* - `tokenId` token must exist and be owned by `from`. | ||
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}. | ||
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. | ||
* | ||
* Emits a {Transfer} event. | ||
*/ | ||
function safeTransferFrom(address from, address to, uint256 tokenId) external; | ||
|
||
/** | ||
* @dev Transfers `tokenId` token from `from` to `to`. | ||
* | ||
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. | ||
* | ||
* Requirements: | ||
* | ||
* - `from` cannot be the zero address. | ||
* - `to` cannot be the zero address. | ||
* - `tokenId` token must be owned by `from`. | ||
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. | ||
* | ||
* Emits a {Transfer} event. | ||
*/ | ||
function transferFrom(address from, address to, uint256 tokenId) external; | ||
|
||
/** | ||
* @dev Gives permission to `to` to transfer `tokenId` token to another account. | ||
* The approval is cleared when the token is transferred. | ||
* | ||
* Only a single account can be approved at a time, so approving the zero address clears previous approvals. | ||
* | ||
* Requirements: | ||
* | ||
* - The caller must own the token or be an approved operator. | ||
* - `tokenId` must exist. | ||
* | ||
* Emits an {Approval} event. | ||
*/ | ||
function approve(address to, uint256 tokenId) external; | ||
|
||
/** | ||
* @dev Returns the account approved for `tokenId` token. | ||
* | ||
* Requirements: | ||
* | ||
* - `tokenId` must exist. | ||
*/ | ||
function getApproved(uint256 tokenId) external view returns (address operator); | ||
|
||
/** | ||
* @dev Approve or remove `operator` as an operator for the caller. | ||
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller. | ||
* | ||
* Requirements: | ||
* | ||
* - The `operator` cannot be the caller. | ||
* | ||
* Emits an {ApprovalForAll} event. | ||
*/ | ||
function setApprovalForAll(address operator, bool _approved) external; | ||
|
||
/** | ||
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`. | ||
* | ||
* See {setApprovalForAll} | ||
*/ | ||
function isApprovedForAll(address owner, address operator) external view returns (bool); | ||
|
||
/** | ||
* @dev Safely transfers `tokenId` token from `from` to `to`. | ||
* | ||
* Requirements: | ||
* | ||
* - `from` cannot be the zero address. | ||
* - `to` cannot be the zero address. | ||
* - `tokenId` token must exist and be owned by `from`. | ||
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}. | ||
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer. | ||
* | ||
* Emits a {Transfer} event. | ||
*/ | ||
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-License-Identifier: MIT | ||
// taken from openzeppelin@3.4.2 and updated the solidity version to fix remapping issues due to different location of the file | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import './IERC721.sol'; | ||
|
||
/** | ||
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension | ||
* @dev See https://eips.ethereum.org/EIPS/eip-721 | ||
*/ | ||
interface IERC721Enumerable is IERC721 { | ||
/** | ||
* @dev Returns the total amount of tokens stored by the contract. | ||
*/ | ||
function totalSupply() external view returns (uint256); | ||
|
||
/** | ||
* @dev Returns a token ID owned by `owner` at a given `index` of its token list. | ||
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens. | ||
*/ | ||
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId); | ||
|
||
/** | ||
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract. | ||
* Use along with {totalSupply} to enumerate all tokens. | ||
*/ | ||
function tokenByIndex(uint256 index) external view returns (uint256); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
// taken from openzeppelin@3.4.2 and updated the solidity version to fix remapping issues due to different location of the file | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import './IERC721.sol'; | ||
|
||
/** | ||
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension | ||
* @dev See https://eips.ethereum.org/EIPS/eip-721 | ||
*/ | ||
interface IERC721Metadata is IERC721 { | ||
/** | ||
* @dev Returns the token collection name. | ||
*/ | ||
function name() external view returns (string memory); | ||
|
||
/** | ||
* @dev Returns the token collection symbol. | ||
*/ | ||
function symbol() external view returns (string memory); | ||
|
||
/** | ||
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. | ||
*/ | ||
function tokenURI(uint256 tokenId) external view returns (string memory); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
solmate/=lib/solmate/ | ||
permit2/=lib/permit2/ | ||
forge-std/=lib/forge-std/src/ | ||
@openzeppelin/=node_modules/@openzeppelin | ||
@openzeppelin/contracts/token/ERC721/=lib/ERC721 | ||
@openzeppelin/contracts-v4=node_modules/@openzeppelin/contracts-v4 | ||
dianakocsis marked this conversation as resolved.
Show resolved
Hide resolved
hensha256 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@uniswap=node_modules/@uniswap |
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.
this is separate to this PR but I think this is odd.. to have SECOND_IF_BOUNDARY as a command? Cause its not really a command.. why not just make the logic command < Command. ERC721_PERMIT? or basically just whatever the command that exists on that boundary
@hensha256 ?
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.
yeah we just thought it was easier to read in the dispatcher to have boundaries... but i see that its confusing to have it in the commands file
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.
I guess you could make it a separate constant and just the only downside is we have two constants equal to the same value?