Skip to content

Commit

Permalink
👷 add setAuctionCooldown and make vault ownable
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Oct 24, 2024
1 parent 3f355ff commit e0f6925
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
3 changes: 2 additions & 1 deletion script/Deploy.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {Script} from "lib/forge-std/src/Script.sol";
contract Setup is Script {

function deploySystem(
address owner,
address token,
address usdc,
address stakingRewards,
Expand All @@ -32,7 +33,7 @@ contract Setup is Script {
public
returns (KSXVault ksxVault)
{
ksxVault = new KSXVault(token, usdc, stakingRewards, auctionFactory, decimalOffset, timeOffset);
ksxVault = new KSXVault(owner, token, usdc, stakingRewards, auctionFactory, decimalOffset, timeOffset);

// deploy ERC1967 proxy and set implementation to ksxVault
Proxy proxy = new Proxy(address(ksxVault), "");
Expand Down
24 changes: 22 additions & 2 deletions src/KSXVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import {ERC4626} from
import {IStakingRewardsV2} from "@token/interfaces/IStakingRewardsV2.sol";
import {AuctionFactory} from "./AuctionFactory.sol";
import {Auction} from "./Auction.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

/// @title KSXVault Contract
/// @notice KSX ERC4626 Vault
/// @author Flocqst ([email protected])
contract KSXVault is ERC4626 {
contract KSXVault is ERC4626, Ownable {

/*///////////////////////////////////////////////////////////////
CONSTANTS/IMMUTABLES
Expand All @@ -20,6 +21,12 @@ contract KSXVault is ERC4626 {
/// @notice max amount of days the time can be offset by
uint internal constant MAX_OFFSET_DAYS = 6;

/// @notice min auction cooldown
uint internal constant MIN_AUCTION_COOLDOWN = 1 days;

/// @notice max auction cooldown
uint internal constant MAX_AUCTION_COOLDOWN = 1 weeks;

/// @notice Decimal offset used for calculating the conversion rate between
/// KWENTA and KSX.
/// @dev Set to 3 to ensure the initial fixed ratio of 1,000 KSX per KWENTA
Expand Down Expand Up @@ -58,6 +65,9 @@ contract KSXVault is ERC4626 {
/// @notice track last time the auction was started
uint256 public lastAuctionStartTime;

/// @notice the cooldown period for auctions
uint256 public auctionCooldown;

/// @notice the week offset in seconds
uint256 internal immutable timeOffset;

Expand All @@ -66,6 +76,7 @@ contract KSXVault is ERC4626 {
//////////////////////////////////////////////////////////////*/

/// @notice Constructs the KSXVault contract
/// @param _owner The owner of the contract (access to setAuctionCooldown)
/// @param _token Kwenta token address
/// @param _usdc USDC token address
/// @param _stakingRewards Kwenta v2 staking rewards contract
Expand All @@ -74,6 +85,7 @@ contract KSXVault is ERC4626 {
/// underlying asset's decimals and the vault decimals
/// @param _daysToOffsetBy the number of days to offset the week by
constructor(
address _owner,
address _token,
address _usdc,
address _stakingRewards,
Expand All @@ -83,13 +95,16 @@ contract KSXVault is ERC4626 {
)
ERC4626(IERC20(_token))
ERC20("KSX Vault", "KSX")
Ownable(_owner)
{
decimalOffset = _decimalOffset;
STAKING_REWARDS = IStakingRewardsV2(_stakingRewards);
KWENTA = ERC20(_token);
USDC = IERC20(_usdc);
auctionFactory = AuctionFactory(_auctionFactory);

auctionCooldown = MAX_AUCTION_COOLDOWN;

if (_daysToOffsetBy > MAX_OFFSET_DAYS) {
revert OffsetTooBig();
}
Expand All @@ -104,7 +119,7 @@ contract KSXVault is ERC4626 {
}

/*//////////////////////////////////////////////////////////////
START AUCTION FUNCTIONS
AUCTION FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @notice Starts the auction with the USDC balance of the vault
Expand Down Expand Up @@ -132,6 +147,11 @@ contract KSXVault is ERC4626 {

}

function setAuctionCooldown(uint256 _auctionCooldown) public onlyOwner() {
require(_auctionCooldown >= MIN_AUCTION_COOLDOWN && _auctionCooldown <= MAX_AUCTION_COOLDOWN, "KSXVault: Invalid cooldown");
auctionCooldown = _auctionCooldown;
}

/// @notice Checks if the auction is ready to start
function auctionReady() public view returns (bool) {
if (_startOfWeek(block.timestamp) > lastAuctionStartTime) {
Expand Down
4 changes: 4 additions & 0 deletions test/KSXVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ contract KSXVaultTest is Bootstrap {
vm.stopPrank();
}

}

contract KSXVaultAuctionTest is KSXVaultTest {

function test_auctionReady() public {
assertEq(ksxVault.auctionReady(), false);
assertEq(block.timestamp, 1);
Expand Down
5 changes: 3 additions & 2 deletions test/utils/Bootstrap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract Bootstrap is Test, Constants {

function initializeLocal(address _token, address _usdc, address _stakingRewards, address _auctionFactory, uint8 _decimalsOffset, uint256 _daysToOffsetBy) internal {
BootstrapLocal bootstrap = new BootstrapLocal();
(address ksxVaultAddress) = bootstrap.init(_token, _usdc, _stakingRewards, _auctionFactory, _decimalsOffset, _daysToOffsetBy);
(address ksxVaultAddress) = bootstrap.init(PDAOADDR, _token, _usdc, _stakingRewards, _auctionFactory, _decimalsOffset, _daysToOffsetBy);

decimalsOffset = _decimalsOffset;
TOKEN = IERC20(_token);
Expand All @@ -46,6 +46,7 @@ contract Bootstrap is Test, Constants {
contract BootstrapLocal is Setup {

function init(
address _owner,
address _token,
address _usdc,
address _stakingRewards,
Expand All @@ -56,7 +57,7 @@ contract BootstrapLocal is Setup {
public
returns (address)
{
(KSXVault ksxvault) = Setup.deploySystem(_token, _usdc, _stakingRewards, _auctionFactory, _decimalsOffset, _timeOffset);
(KSXVault ksxvault) = Setup.deploySystem(_owner, _token, _usdc, _stakingRewards, _auctionFactory, _decimalsOffset, _timeOffset);

return (address(ksxvault));
}
Expand Down

0 comments on commit e0f6925

Please sign in to comment.