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

Changed variable names #37

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 13 additions & 13 deletions src/NovaAdapterBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,26 @@ import {SafeTransferLib} from "@solmate/utils/SafeTransferLib.sol";
abstract contract NovaAdapterBase is INovaAdapterBase {
using SafeTransferLib for ERC20;

address immutable sDAI;
address immutable savings;
address immutable asset;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's replace asset with stable so that we use just two variable names: stable and savings

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we also have uint256 assets for the amount to deposit, should I rename that too (to amountInStable for example) ?


constructor(address _asset, address _sDAI) {
constructor(address _asset, address _savings) {
asset = _asset;
sDAI = _sDAI;
savings = _savings;
}

function deposit(uint256 assets) external returns (bool, uint256) {
ERC20(asset).safeTransferFrom(msg.sender, address(this), assets);

(, int256 sDaiOut) = _swap(int256(assets), true);
uint256 sDaiToTransfer = uint256(-sDaiOut);
ERC20(sDAI).safeTransfer(msg.sender, sDaiToTransfer);
(, int256 savingsOut) = _swap(int256(assets), true);
uint256 savingsToTransfer = uint256(-savingsOut);
ERC20(savings).safeTransfer(msg.sender, savingsToTransfer);

return (true, sDaiToTransfer);
return (true, savingsToTransfer);
}

function withdraw(uint256 shares) external returns (bool, uint256) {
ERC20(sDAI).safeTransferFrom(msg.sender, address(this), shares);
ERC20(savings).safeTransferFrom(msg.sender, address(this), shares);

(int256 assets, ) = _swap(int256(shares), false);
uint256 assetsToTransfer = uint256(-assets);
Expand All @@ -37,17 +37,17 @@ abstract contract NovaAdapterBase is INovaAdapterBase {
}

/**
* @notice Performs a swap operation between the stable asset and sDAI.
* @notice Performs a swap operation between the stable asset and savings.
* @dev This function interacts with the pool to execute the swap.
* @param amount The amount to be swapped.
* @param fromStableTosDai A boolean indicating the direction of the swap.
* - `true` for swapping from the stable asset to sDAI.
* - `false` for swapping from sDAI to the stable asset.
* @param fromStableToSavings A boolean indicating the direction of the swap.
* - `true` for swapping from the stable asset to savings.
* - `false` for swapping from savings to the stable asset.
* @return amount0 The amount of token0 involved in the swap.
* @return amount1 The amount of token1 involved in the swap.
*/
function _swap(
int256 amount,
bool fromStableTosDai
bool fromStableToSavings
) internal virtual returns (int256, int256);
}
18 changes: 9 additions & 9 deletions src/NovaVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract NovaVault is INovaVault, Ownable, ReentrancyGuard {
using SafeTransferLib for ERC20;

mapping(address => address) public _novaAdapters;
address immutable sDAI;
address immutable savings;

modifier onlyNonZero(address asset) {
if (asset == address(0)) {
Expand All @@ -29,11 +29,11 @@ contract NovaVault is INovaVault, Ownable, ReentrancyGuard {
_;
}
constructor(
address _sDAI,
address _savings,
address[] memory stables,
address[] memory novaAdapters
) Ownable() onlyNonZero(_sDAI) {
sDAI = _sDAI;
) Ownable() onlyNonZero(_savings) {
savings = _savings;
_approveNovaAdapters(stables, novaAdapters);
}

Expand Down Expand Up @@ -92,16 +92,16 @@ contract NovaVault is INovaVault, Ownable, ReentrancyGuard {
(bool success, bytes memory data) = adapter.call(
abi.encodeWithSignature("deposit(uint256)", assets)
);
(bool successDeposit, uint256 sDaiAmount) = abi.decode(
(bool successDeposit, uint256 savingsAmount) = abi.decode(
data,
(bool, uint256)
);
require(success && successDeposit, "Deposit failed");

ERC20(sDAI).safeTransfer(msg.sender, sDaiAmount);
ERC20(savings).safeTransfer(msg.sender, savingsAmount);

emit Referral(referral, msg.sender, assets);
return (true, sDaiAmount);
return (true, savingsAmount);
}

function withdraw(
Expand All @@ -116,8 +116,8 @@ contract NovaVault is INovaVault, Ownable, ReentrancyGuard {
{
address adapter = _novaAdapters[stable];

ERC20(sDAI).safeTransferFrom(msg.sender, address(this), shares);
ERC20(sDAI).safeApprove(adapter, shares);
ERC20(savings).safeTransferFrom(msg.sender, address(this), shares);
ERC20(savings).safeApprove(adapter, shares);

(bool success, bytes memory data) = adapter.call(
abi.encodeWithSignature("withdraw(uint256)", shares)
Expand Down
18 changes: 9 additions & 9 deletions src/adapters/NovaAdapterVeloCLPool.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
pragma solidity 0.8.17;

import {IVelodromeCLPool} from "../interfaces/IVelodromeCLPool.sol";
import {NovaAdapterBase} from "../NovaAdapterBase.sol";
Expand All @@ -17,19 +17,19 @@ contract NovaAdapterVeloCLPool is NovaAdapterBase {

constructor(
address _asset,
address _sDAI,
address _savings,
address _pool
) NovaAdapterBase(_asset, _sDAI) {
) NovaAdapterBase(_asset, _savings) {
veloPool = IVelodromeCLPool(_pool);
veloToken0 = veloPool.token0();
veloToken1 = veloPool.token1();

if ((veloToken0 == asset) && (veloToken1 == sDAI)) {
if ((veloToken0 == asset) && (veloToken1 == savings)) {
isStableFirst = true;
} else if ((veloToken0 == sDAI) && (veloToken1 == asset)) {
} else if ((veloToken0 == savings) && (veloToken1 == asset)) {
isStableFirst = false;
} else {
revert("Velodrome pool should be made of `_asset` and `sDAI`!");
revert("Velodrome pool should be made of `_asset` and `savings`!");
}
}

Expand All @@ -50,15 +50,15 @@ contract NovaAdapterVeloCLPool is NovaAdapterBase {

function _swap(
int256 amount,
bool fromStableTosDai
bool fromStableToSavings
) internal override returns (int256, int256) {
(uint160 sqrtPriceX96, , , , , ) = veloPool.slot0();
uint160 num = fromStableTosDai ? 95 : 105;
uint160 num = fromStableToSavings ? 95 : 105;
int256 sign = isStableFirst ? int256(1) : int256(-1);

(int256 amount0, int256 amount1) = veloPool.swap(
address(this),
fromStableTosDai,
fromStableToSavings,
sign * amount,
(num * sqrtPriceX96) / 100,
""
Expand Down