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

relayer contract #45

Closed
wants to merge 2 commits into from
Closed
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
75 changes: 75 additions & 0 deletions src/tools/AutomanProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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";

interface Automan {
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);
}

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;
}

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) {
address owner = npm.ownerOf(tokenId);
require(allowance[msg.sender][owner], "not allow relayer");
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 returns (uint256 newTokenId, uint128 liquidity, uint256 amount0, uint256 amount1) {
address owner = npm.ownerOf(tokenId);
require(allowance[msg.sender][owner], "not allow relayer");
return automan.rebalance(params, tokenId, feePips, swapData);
}
}
Loading