Skip to content

Commit

Permalink
IProfitPalsVault.sol #1
Browse files Browse the repository at this point in the history
  • Loading branch information
utgarda committed Oct 14, 2023
1 parent fe77c8a commit d1f9406
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 19 deletions.
5 changes: 4 additions & 1 deletion src/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ pragma solidity ^0.8.13;
uint256 constant SHARE_DECIMALS = 6;
address constant SAFE_PROXY_FACTORY_130_POLYGON = 0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2;
address constant SAFE_LOGIC_SINGLETON_POLYGON = 0x3E5c63644E683549055b9Be8653de26E0B4CD36E;
address constant USDC_POLYGON = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174;
address constant USDC_POLYGON = 0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174;
address constant WBTC_POLYGON = 0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6;

address constant UNISWAP_PERMIT2_POLYGON = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
34 changes: 29 additions & 5 deletions src/ProfitPalsVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,32 @@ import "@safe-contracts/proxies/GnosisSafeProxyFactory.sol";
*/
contract ProfitPalsVault is IProfitPalsVault, ERC4626 {
IERC20 public immutable anchorCurrency;

address public immutable operator;
uint256 public immutable operatorFee;
IERC20[] public allowedTokens;
/**
* @param anchorCurrency_ - The main or anchor ERC20 token that the vault will manage.
* @param name_ - Name of the shares token
* @param symbol_ - Symbol of the shares token
*/
constructor(
address safeProxyFactory,
address safeLogicSingleton,
IERC20 anchorCurrency_,
IERC20[] memory tokens,
uint256 operatorFee_,
string memory name_,
string memory symbol_
string memory symbol_,

address safeProxyFactory,
address safeLogicSingleton
)
ERC4626(anchorCurrency_) ERC20(name_, symbol_){
//TODO init safe account
operator = tx.origin; //TODO think about this
address[] memory owners = new address[](1);
owners[0] = address(this);

anchorCurrency = anchorCurrency_;
operatorFee = operatorFee_;
allowedTokens = tokens;

bytes memory safeAccountSetupData = abi.encodeCall(
GnosisSafe.setup,
Expand All @@ -56,4 +64,20 @@ contract ProfitPalsVault is IProfitPalsVault, ERC4626 {
//TODO add overall Uniswap positions here
return anchorCurrency.balanceOf(address(this));
}

function deposit(uint256 amount) external {

}

function withdraw(uint256 amount) external {

}

function pause() external {

}

function unpause() external {

}
}
9 changes: 5 additions & 4 deletions src/UniswapOnlyGuard.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@safe-contracts/base/GuardManager.sol";

contract UniswapOnlyGuard is Guard {
constructor(){

address immutable permit2;
constructor(address permit2_){
permit2 = permit2_;
}

function checkTransaction(
Expand All @@ -21,7 +22,7 @@ contract UniswapOnlyGuard is Guard {
bytes memory signatures,
address msgSender
) external override {
require(to == address(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D), "Only Uniswap transactions allowed");
require(to == permit2, "Only approvals to Uniswap Permit2 allowed");
}

function checkAfterExecution(bytes32 txHash, bool success) external override {
Expand Down
14 changes: 14 additions & 0 deletions src/interfaces/IProfitPalsVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,19 @@ import "@openzeppelin/token/ERC20/IERC20.sol";
import "@openzeppelin/interfaces/IERC4626.sol";

interface IProfitPalsVault is IERC4626 {
function operator() external view returns (address);

function operatorFee() external view returns (uint256);

function anchorCurrency() external view returns (IERC20);

function allowedTokens(uint256 index) external view returns (IERC20);

function deposit(uint256 amount) external;

function withdraw(uint256 amount) external;

function pause() external;

function unpause() external;
}
8 changes: 7 additions & 1 deletion src/interfaces/IProfitPalsVaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ pragma solidity ^0.8.0;
import "@openzeppelin/token/ERC20/IERC20.sol";

interface IProfitPalsVaultFactory {
function createVault(IERC20 anchorCurrency, string memory name_, string memory symbol_) external returns (address);
function createVault(
IERC20 anchorCurrency,
address[] memory tokens,
uint256 operatorFee,
string memory name_,
string memory symbol_
) external returns (address);

function safeLogicSingleton() external view returns (address);

Expand Down
15 changes: 12 additions & 3 deletions test/DepositAnchorCurrency.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ contract DepositAnchorCurrencyTest is Test {
address USDC_BIG_HOLDER = 0xF977814e90dA44bFA03b6295A0616a897441aceC;

IERC20 usdc = IERC20(USDC_POLYGON);
IERC20 wbtc = IERC20(WBTC_POLYGON);

IERC20[] tokens = new IERC20[](1);
ProfitPalsVault public profitPalsVault;

function setUp() public {
tokens.push(usdc);

profitPalsVault = new ProfitPalsVault(
SAFE_PROXY_FACTORY_130_POLYGON,
SAFE_LOGIC_SINGLETON_POLYGON,
usdc,
"testUSDCVault", "tUSDCv");
tokens,
2000,

"testUSDCVault", "tUSDCv",

SAFE_PROXY_FACTORY_130_POLYGON,
SAFE_LOGIC_SINGLETON_POLYGON
);

vm.startPrank(USDC_BIG_HOLDER);
usdc.transfer(address(this), 1000 * 10 ** 6);
Expand Down
10 changes: 5 additions & 5 deletions test/SetupSafeGuard.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { Test, console2 } from "forge-std/Test.sol";
import {Test, console2} from "forge-std/Test.sol";
import "@openzeppelin/token/ERC20/IERC20.sol";
import {GnosisSafe} from "@safe-contracts/GnosisSafe.sol";
import {GnosisSafeL2} from "@safe-contracts/GnosisSafeL2.sol";
Expand Down Expand Up @@ -37,7 +37,7 @@ contract SetupSafeGuard is Test {
0,
payable(0))
);
GnosisSafeProxy proxy = GnosisSafeProxyFactory(SAFE_PROXY_FACTORY).createProxyWithNonce(
proxy = GnosisSafeProxyFactory(SAFE_PROXY_FACTORY).createProxyWithNonce(
SINGLETON_ADDRESS,
data,
1234567
Expand All @@ -46,7 +46,7 @@ contract SetupSafeGuard is Test {
vm.startPrank(USDC_BIG_HOLDER);
usdc.transfer(address(this), 1000 * 10 ** 6);

payable(address(this)).transfer(10**18);
payable(address(this)).transfer(10 ** 18);
vm.stopPrank();
}

Expand All @@ -64,7 +64,7 @@ contract SetupSafeGuard is Test {
// )

function test_deploySafeAndAddGuard() public {
UniswapOnlyGuard guard = new UniswapOnlyGuard();
UniswapOnlyGuard guard = new UniswapOnlyGuard(UNISWAP_PERMIT2_POLYGON);
// GuardManager.setGuard(address guard)
bytes memory setGuardCallData = abi.encodeCall(
GuardManager.setGuard,
Expand Down

0 comments on commit d1f9406

Please sign in to comment.