Skip to content

Commit

Permalink
feat(contracts): lock and redemption of pounder
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Dec 7, 2023
1 parent c97bdcd commit 53d17d1
Show file tree
Hide file tree
Showing 48 changed files with 1,325 additions and 857 deletions.
4 changes: 2 additions & 2 deletions contracts/script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity 0.8.20;

import { Vault } from "../src/Vault.sol";
import { Zap } from "../src/Zap.sol";
import { Vault } from "../src/Warlord-Vault/Vault.sol";
import { Zap } from "../src/Warlord-Vault/Zap.sol";
import { Swapper } from "../src/Swapper.sol";
import "forge-std/Script.sol";

Expand Down
22 changes: 22 additions & 0 deletions contracts/src/Pounders/ERC1155.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.20;

import { ERC1155 as ERC1155Solady } from "solady/tokens/ERC1155.sol";
import { AOperator, Owned2Step } from "./abstracts/AOperator.sol";

contract ERC1155 is ERC1155Solady, AOperator {
constructor(address definitiveOwner, address initialOperator)
Owned2Step(definitiveOwner)
AOperator(initialOperator)
{ }

function uri(uint256 id) public view override returns (string memory) { }

function mint(address to, uint256 id, uint256 amount, bytes memory data) external onlyOperatorOrOwner {
_mint(to, id, amount, data);
}

function batchBurn(address from, uint256[] memory ids, uint256[] memory amounts) external onlyOperatorOrOwner {
_batchBurn(from, ids, amounts);
}
}
171 changes: 171 additions & 0 deletions contracts/src/Pounders/Swapper.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.20;

import { ERC20 } from "solmate/tokens/ERC20.sol";
import { Owned2Step } from "./utils/Owned2Step.sol";
import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol";
import { Errors } from "./utils/Errors.sol";
import { Allowance } from "./utils/Allowance.sol";

/// @author 0xtekgrinder
/// @title Swapper contract
/// @notice Contract to manage swaps using a router/aggregator
contract Swapper is Owned2Step {
using SafeTransferLib for ERC20;

/**
* @notice Event emitted when the swap router is updated
*/
event SwapRouterUpdated(address oldSwapRouter, address newSwapRouter);
/**
* @notice Event emitted when the token proxy is updated
*/
event TokenTransferAddressUpdated(address oldTokenTransferAddress, address newTokenTransferAddress);
/**
* @notice Event emitted when the vault is updated
*/
event VaultUpdated(address oldVault, address newVault);

/*//////////////////////////////////////////////////////////////
MUTABLE VARIABLES
//////////////////////////////////////////////////////////////*/

/**
* @notice Dex/aggregaor router to call to perform swaps
*/
address public swapRouter;
/**
* @notice Address to allow to swap tokens
*/
address public tokenTransferAddress;
/**
* @notice Address of the ERC4626 vault
*/
address public vault;

/*//////////////////////////////////////////////////////////////
MODIFIERS
//////////////////////////////////////////////////////////////*/

modifier onlyVault() {
if (msg.sender != vault) revert Errors.NotVault();
_;
}

/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/

constructor(address initialOwner, address initialSwapRouter, address initialTokenTransferAddress)
Owned2Step(initialOwner)
{
if (initialSwapRouter == address(0) || initialTokenTransferAddress == address(0)) revert Errors.ZeroAddress();

swapRouter = initialSwapRouter;
tokenTransferAddress = initialTokenTransferAddress;
}

/*//////////////////////////////////////////////////////////////
ADMIN LOGIC
//////////////////////////////////////////////////////////////*/

/**
* @notice Set the dex/aggregator router to call to perform swaps
* @param newSwapRouter address of the router
* @custom:requires owner
*/
function setSwapRouter(address newSwapRouter) external onlyOwner {
if (newSwapRouter == address(0)) revert Errors.ZeroAddress();

address oldSwapRouter = swapRouter;
swapRouter = newSwapRouter;

emit SwapRouterUpdated(oldSwapRouter, newSwapRouter);
}

/**
* @notice Set the token proxy address to allow to swap tokens
* @param newTokenTransferAddress address of the token proxy
* @custom:requires owner
*/
function setTokenTransferAddress(address newTokenTransferAddress) external onlyOwner {
if (newTokenTransferAddress == address(0)) revert Errors.ZeroAddress();

address oldtokenTransferAddress = tokenTransferAddress;
tokenTransferAddress = newTokenTransferAddress;

emit TokenTransferAddressUpdated(oldtokenTransferAddress, newTokenTransferAddress);
}

/**
* @notice Set the vault address
* @param newVault address of the vault
* @custom:requires owner
*/
function setVault(address newVault) external onlyOwner {
if (newVault == address(0)) revert Errors.ZeroAddress();

address oldVault = vault;
vault = newVault;

emit VaultUpdated(oldVault, newVault);
}

/**
* @notice Recover ERC2O tokens in the contract
* @dev Recover ERC2O tokens in the contract
* @param token Address of the ERC2O token
* @return bool: success
* @custom:requires owner
*/
function recoverERC20(address token) external onlyOwner returns (bool) {
if (token == address(0)) revert Errors.ZeroAddress();

uint256 amount = ERC20(token).balanceOf(address(this));
if (amount == 0) revert Errors.ZeroValue();

ERC20(token).safeTransfer(owner, amount);

return true;
}

/*//////////////////////////////////////////////////////////////
SWAP LOGIC
//////////////////////////////////////////////////////////////*/

/**
* @notice Swap tokens using the router/aggregator
* @dev The calldatas should set the recipient of the tokens to the vault
* @param tokens array of tokens to swap
* @param callDatas array of bytes to call the router/aggregator
*/
function swap(address[] calldata tokens, bytes[] calldata callDatas) external onlyVault {
uint256 length = tokens.length;

for (uint256 i; i < length;) {
address token = tokens[i];
Allowance._approveTokenIfNeeded(token, tokenTransferAddress);
_performRouterSwap(callDatas[i]);
unchecked {
++i;
}
}
}

/**
* @notice Perform the swap using the router/aggregator
* @param callData bytes to call the router/aggregator
*/
function _performRouterSwap(bytes calldata callData) internal {
(bool success, bytes memory retData) = swapRouter.call(callData);

if (!success) {
if (retData.length != 0) {
assembly {
revert(add(32, retData), mload(retData))
}
}
revert Errors.SwapError();
}
}
}
82 changes: 82 additions & 0 deletions contracts/src/Pounders/abstracts/AFees.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.20;

import { Owned2Step } from "../utils/Owned2Step.sol";
import { Errors } from "../utils/Errors.sol";

/// @author 0xtekgrinder
/// @title AFees
/// @notice Abstract contract to allow access only to operator or owner
abstract contract AFees is Owned2Step {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/*//////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/

/**
* @notice Max BPS value (100%)
*/
uint256 public constant MAX_BPS = 10_000;

uint256 public constant FEE_DENOMINATOR = 10_000;

/*//////////////////////////////////////////////////////////////
MUTABLE VARIABLES
//////////////////////////////////////////////////////////////*/

/**
* @notice fee to be applied when harvesting rewards
*/
uint256 public harvestFee;
/**
* @notice address to receive the harvest fee
*/
address public feeRecipient;

uint256 public redemptionFeeMax;

uint256 public protocolFee;

/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/

constructor(uint256 initialHarvestFee, address initialFeeRecipient) {
if (initialFeeRecipient == address(0)) revert Errors.ZeroAddress();
if (initialHarvestFee > MAX_BPS) {
revert Errors.InvalidFee();
}

harvestFee = initialHarvestFee;
feeRecipient = initialFeeRecipient;
}

/*//////////////////////////////////////////////////////////////
FEES LOGIC
//////////////////////////////////////////////////////////////*/

/*
function setHarvestFee(uint256 newHarvestFee) external virtual onlyOwner {
if (newHarvestFee > MAX_BPS) {
revert Errors.InvalidFee();
}
uint256 oldHarvestFee = harvestFee;
harvestFee = newHarvestFee;
emit HarvestFeeUpdated(oldHarvestFee, newHarvestFee);
}
function setFeeRecipient(address newFeeRecipient) external virtual onlyOwner {
if (newFeeRecipient == address(0)) revert Errors.ZeroAddress();
address oldFeeRecipient = feeRecipient;
feeRecipient = newFeeRecipient;
emit FeeRecipientUpdated(oldFeeRecipient, newFeeRecipient);
}
*/
}
File renamed without changes.
Loading

0 comments on commit 53d17d1

Please sign in to comment.