Skip to content
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
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
297 changes: 297 additions & 0 deletions src/tools/AutomanProxy.sol
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 {
Copy link
Contributor

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?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete 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);
}
}
Loading