Skip to content

Commit

Permalink
πŸ‘·πŸ“š rename offset to decimalOffset
Browse files Browse the repository at this point in the history
  • Loading branch information
cmontecoding committed Oct 17, 2024
1 parent db9628b commit 1e0be95
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/KSXVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract KSXVault is ERC4626 {
/// @dev Set to 3 to ensure the initial fixed ratio of 1,000 KSX per KWENTA
/// further protect against inflation attacks
/// (https://docs.openzeppelin.com/contracts/4.x/erc4626#inflation-attack)
uint8 public immutable offset;
uint8 public immutable decimalOffset;

/// @notice Kwenta's StakingRewards contract
IStakingRewardsV2 internal immutable STAKING_REWARDS;
Expand All @@ -39,6 +39,9 @@ contract KSXVault is ERC4626 {
/// @notice Thrown when trying to start an auction when it is not ready
error AuctionNotReady();

/// @notice error when offset is 7 or more days
error OffsetTooBig();

/*///////////////////////////////////////////////////////////////
STATE
///////////////////////////////////////////////////////////////*/
Expand All @@ -56,19 +59,19 @@ contract KSXVault is ERC4626 {
/// @notice Constructs the KSXVault contract
/// @param _token Kwenta token address
/// @param _stakingRewards Kwenta v2 staking rewards contract
/// @param _offset offset in the decimal representation between the
/// @param _decimalOffset offset in the decimal representation between the
/// underlying asset's decimals and the vault decimals
/// @param _daysToOffsetBy the number of days to offset the week by
constructor(
address _token,
address _stakingRewards,
uint8 _offset,
uint8 _decimalOffset,
uint256 _daysToOffsetBy
)
ERC4626(IERC20(_token))
ERC20("KSX Vault", "KSX")
{
offset = _offset;
decimalOffset = _decimalOffset;
STAKING_REWARDS = IStakingRewardsV2(_stakingRewards);
KWENTA = ERC20(_token);

Expand All @@ -82,7 +85,7 @@ contract KSXVault is ERC4626 {
/// @dev This function is used internally by the ERC4626 implementation
/// @return The decimal offset value
function _decimalsOffset() internal view virtual override returns (uint8) {
return offset;
return decimalOffset;
}

/*//////////////////////////////////////////////////////////////
Expand Down
10 changes: 5 additions & 5 deletions test/KSXVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ contract KSXVaultTest is Bootstrap {

// Asserts decimals offset is correctly set to 3
function test_vault_decimalsOffset() public {
assertEq(ksxVault.offset(), 3);
assertEq(ksxVault.decimalOffset(), 3);
}

// Asserts correct deposit at 1000 shares ratio
Expand All @@ -44,7 +44,7 @@ contract KSXVaultTest is Bootstrap {
vm.startPrank(alice);
depositToken.approve(address(ksxVault), amount);
ksxVault.deposit(1 ether, alice);
assertEq(ksxVault.balanceOf(alice), amount * (10 ** ksxVault.offset()));
assertEq(ksxVault.balanceOf(alice), amount * (10 ** ksxVault.decimalOffset()));
assertEq(stakingRewards.stakedBalanceOf(address(ksxVault)), amount);
vm.stopPrank();
}
Expand All @@ -60,7 +60,7 @@ contract KSXVaultTest is Bootstrap {
assertEq(ksxVault.balanceOf(alice), amount);
assertEq(
stakingRewards.stakedBalanceOf(address(ksxVault)),
amount / (10 ** ksxVault.offset())
amount / (10 ** ksxVault.decimalOffset())
);
vm.stopPrank();
}
Expand All @@ -72,7 +72,7 @@ contract KSXVaultTest is Bootstrap {
vm.startPrank(alice);
depositToken.approve(address(ksxVault), amount);
ksxVault.deposit(amount, alice);
assertEq(ksxVault.balanceOf(alice), amount * (10 ** ksxVault.offset()));
assertEq(ksxVault.balanceOf(alice), amount * (10 ** ksxVault.decimalOffset()));
assertEq(stakingRewards.stakedBalanceOf(address(ksxVault)), amount);

ksxVault.withdraw(amount, alice, alice);
Expand All @@ -90,7 +90,7 @@ contract KSXVaultTest is Bootstrap {
assertEq(stakingRewards.stakedBalanceOf(address(ksxVault)), amount / 1000);
assertEq(
stakingRewards.stakedBalanceOf(address(ksxVault)),
amount / (10 ** ksxVault.offset())
amount / (10 ** ksxVault.decimalOffset())
);

ksxVault.redeem(amount, alice, alice);
Expand Down

0 comments on commit 1e0be95

Please sign in to comment.