-
Notifications
You must be signed in to change notification settings - Fork 7
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
automan proxy contract #47
Open
kan-aperture
wants to merge
4
commits into
Aperture-Finance:main
Choose a base branch
from
kan-aperture:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 |
---|---|---|
@@ -0,0 +1,297 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.18; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import {INonfungiblePositionManager as INPM} from "@aperture_finance/uni-v3-lib/src/interfaces/INonfungiblePositionManager.sol"; | ||
import {IAutoman} from "../interfaces/IAutoman.sol"; | ||
|
||
interface Automan { | ||
function increaseLiquidity( | ||
INPM.IncreaseLiquidityParams memory params | ||
) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1); | ||
|
||
function increaseLiquidityOptimal( | ||
INPM.IncreaseLiquidityParams memory params, | ||
bytes calldata swapData | ||
) external payable returns (uint128 liquidity, uint256 amount0, uint256 amount1); | ||
|
||
function decreaseLiquidity( | ||
INPM.DecreaseLiquidityParams memory params, | ||
uint256 feePips | ||
) external returns (uint256 amount0, uint256 amount1); | ||
|
||
function decreaseLiquidity( | ||
INPM.DecreaseLiquidityParams memory params, | ||
uint256 feePips, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external returns (uint256 amount0, uint256 amount1); | ||
|
||
function decreaseLiquiditySingle( | ||
INPM.DecreaseLiquidityParams memory params, | ||
bool zeroForOne, | ||
uint256 feePips, | ||
bytes calldata swapData | ||
) external returns (uint256 amount); | ||
|
||
function decreaseLiquiditySingle( | ||
INPM.DecreaseLiquidityParams memory params, | ||
bool zeroForOne, | ||
uint256 feePips, | ||
bytes calldata swapData, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external returns (uint256 amount); | ||
|
||
function rebalance( | ||
INPM.MintParams memory params, | ||
uint256 tokenId, | ||
uint256 feePips, | ||
bytes calldata swapData, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1); | ||
|
||
function rebalance( | ||
INPM.MintParams memory params, | ||
uint256 tokenId, | ||
uint256 feePips, | ||
bytes calldata swapData | ||
) external returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1); | ||
|
||
function removeLiquidity( | ||
INPM.DecreaseLiquidityParams memory params, | ||
uint256 feePips | ||
) external returns (uint256 amount0, uint256 amount1); | ||
|
||
function removeLiquidity( | ||
INPM.DecreaseLiquidityParams memory params, | ||
uint256 feePips, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external returns (uint256 amount0, uint256 amount1); | ||
|
||
function removeLiquiditySingle( | ||
INPM.DecreaseLiquidityParams memory params, | ||
bool zeroForOne, | ||
uint256 feePips, | ||
bytes calldata swapData | ||
) external returns (uint256 amount); | ||
|
||
function removeLiquiditySingle( | ||
INPM.DecreaseLiquidityParams memory params, | ||
bool zeroForOne, | ||
uint256 feePips, | ||
bytes calldata swapData, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external returns (uint256 amount); | ||
|
||
function reinvest( | ||
INPM.IncreaseLiquidityParams memory params, | ||
uint256 feePips, | ||
bytes calldata swapData | ||
) external returns (uint128 liquidity, uint256 amount0, uint256 amount1); | ||
|
||
function reinvest( | ||
INPM.IncreaseLiquidityParams memory params, | ||
uint256 feePips, | ||
bytes calldata swapData, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external returns (uint128 liquidity, uint256 amount0, uint256 amount1); | ||
} | ||
|
||
contract AutomanRelayerProxy is Ownable, Automan { | ||
mapping(address => mapping(address => bool)) public allowance; | ||
INPM public npm; | ||
Automan public automan; | ||
constructor(INPM _npm, Automan _automan) Ownable(msg.sender) { | ||
npm = _npm; | ||
automan = _automan; | ||
} | ||
|
||
function setAllowance(address[] calldata relayers, address[] calldata owners, bool value) external onlyOwner { | ||
uint lrelayer = relayers.length; | ||
uint lowners = owners.length; | ||
for (uint i = 0; i < lrelayer; i++) { | ||
for (uint j = 0; j < lowners; j++) { | ||
allowance[relayers[i]][owners[j]] = value; | ||
} | ||
} | ||
} | ||
|
||
function updateNpm(INPM _npm) external onlyOwner { | ||
npm = _npm; | ||
} | ||
|
||
modifier onlyAllowedRelayer(uint256 tokenId) { | ||
require(allowance[msg.sender][npm.ownerOf(tokenId)], "not allow relayer"); | ||
_; | ||
} | ||
|
||
function rebalance( | ||
INPM.MintParams memory params, | ||
uint256 tokenId, | ||
uint256 feePips, | ||
bytes calldata swapData, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) | ||
external | ||
onlyAllowedRelayer(tokenId) | ||
returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1) | ||
{ | ||
return automan.rebalance(params, tokenId, feePips, swapData, permitDeadline, v, r, s); | ||
} | ||
|
||
function rebalance( | ||
INPM.MintParams memory params, | ||
uint256 tokenId, | ||
uint256 feePips, | ||
bytes calldata swapData | ||
) | ||
external | ||
onlyAllowedRelayer(tokenId) | ||
returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1) | ||
{ | ||
return automan.rebalance(params, tokenId, feePips, swapData); | ||
} | ||
|
||
function increaseLiquidity( | ||
INPM.IncreaseLiquidityParams memory params | ||
) | ||
external | ||
payable | ||
onlyAllowedRelayer(params.tokenId) | ||
returns (uint128 liquidity, uint256 amount0, uint256 amount1) | ||
{ | ||
return automan.increaseLiquidity(params); | ||
} | ||
|
||
function increaseLiquidityOptimal( | ||
INPM.IncreaseLiquidityParams memory params, | ||
bytes calldata swapData | ||
) | ||
external | ||
payable | ||
onlyAllowedRelayer(params.tokenId) | ||
returns (uint128 liquidity, uint256 amount0, uint256 amount1) | ||
{ | ||
return automan.increaseLiquidityOptimal(params, swapData); | ||
} | ||
|
||
function decreaseLiquidity( | ||
INPM.DecreaseLiquidityParams memory params, | ||
uint256 feePips | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint256 amount0, uint256 amount1) { | ||
return automan.decreaseLiquidity(params, feePips); | ||
} | ||
|
||
function decreaseLiquidity( | ||
INPM.DecreaseLiquidityParams memory params, | ||
uint256 feePips, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint256 amount0, uint256 amount1) { | ||
return automan.decreaseLiquidity(params, feePips, permitDeadline, v, r, s); | ||
} | ||
|
||
function decreaseLiquiditySingle( | ||
INPM.DecreaseLiquidityParams memory params, | ||
bool zeroForOne, | ||
uint256 feePips, | ||
bytes calldata swapData | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint256 amount) { | ||
return automan.decreaseLiquiditySingle(params, zeroForOne, feePips, swapData); | ||
} | ||
|
||
function decreaseLiquiditySingle( | ||
INPM.DecreaseLiquidityParams memory params, | ||
bool zeroForOne, | ||
uint256 feePips, | ||
bytes calldata swapData, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint256 amount) { | ||
return automan.decreaseLiquiditySingle(params, zeroForOne, feePips, swapData, permitDeadline, v, r, s); | ||
} | ||
|
||
function removeLiquidity( | ||
INPM.DecreaseLiquidityParams memory params, | ||
uint256 feePips | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint256 amount0, uint256 amount1) { | ||
return automan.removeLiquidity(params, feePips); | ||
} | ||
|
||
function removeLiquidity( | ||
INPM.DecreaseLiquidityParams memory params, | ||
uint256 feePips, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint256 amount0, uint256 amount1) { | ||
return automan.removeLiquidity(params, feePips, permitDeadline, v, r, s); | ||
} | ||
|
||
function removeLiquiditySingle( | ||
INPM.DecreaseLiquidityParams memory params, | ||
bool zeroForOne, | ||
uint256 feePips, | ||
bytes calldata swapData | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint256 amount) { | ||
return automan.removeLiquiditySingle(params, zeroForOne, feePips, swapData); | ||
} | ||
|
||
function removeLiquiditySingle( | ||
INPM.DecreaseLiquidityParams memory params, | ||
bool zeroForOne, | ||
uint256 feePips, | ||
bytes calldata swapData, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint256 amount) { | ||
return automan.removeLiquiditySingle(params, zeroForOne, feePips, swapData, permitDeadline, v, r, s); | ||
} | ||
|
||
function reinvest( | ||
INPM.IncreaseLiquidityParams memory params, | ||
uint256 feePips, | ||
bytes calldata swapData | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint128 liquidity, uint256 amount0, uint256 amount1) { | ||
return automan.reinvest(params, feePips, swapData); | ||
} | ||
|
||
function reinvest( | ||
INPM.IncreaseLiquidityParams memory params, | ||
uint256 feePips, | ||
bytes calldata swapData, | ||
uint256 permitDeadline, | ||
uint8 v, | ||
bytes32 r, | ||
bytes32 s | ||
) external onlyAllowedRelayer(params.tokenId) returns (uint128 liquidity, uint256 amount0, uint256 amount1) { | ||
return automan.reinvest(params, feePips, swapData, permitDeadline, v, r, s); | ||
} | ||
} |
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.
Use
src/interfaces/IAutoman.sol
?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.
done
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.
Delete
interface Automan
?