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

Add NovaVault and interfaces #13

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
75 changes: 75 additions & 0 deletions src/NovaVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Errors} from "./libraries/Errors.sol";
import {INovaVault} from "./interfaces/INovaVault.sol";
import {INovaAdapterBase} from "./interfaces/INovaAdapterBase.sol";

contract NovaVault is INovaVault {
mapping(address => address) public _novaAdapters;

function constructor(
address[] calldata stables,
address[] calldata novaAdapters
) {
_approveNovaAdapters(stables, novaAdapters);
}

function _approveNovaAdapters(
address[] calldata stables,
address[] calldata novaAdapters,
) internal {
require(
lakonema2000 marked this conversation as resolved.
Show resolved Hide resolved
stables.length == novaAdapters.length,
Errors.MISMATCHING_ARRAYS_LENGTH
);
for (uint256 i = 0; i < stables.length; i++) {
_approveAdapter(stables[i], novaAdapters[i]);
}
}

function _approveAdapter(
address stable,
address adapter
) internal {
require(stable != address(0), Errors.INVALID_ADDRESS);

require(
_novaAdapters[stable] == address(0),
Errors.ADAPTER_ALREADY_APPROVED
);

ERC20 underlyingAsset = INovaAdapterBase(adapter).asset();
require(
address(underlyingAsset) == stable,
Errors.INVALID_STABLE_TO_ADAPTER_MAPPING
);

_novaAdapters[stable] = adapter;
emit ApprovedAdapter(stable, adapter);
}

function deposit(address stable, uint256 assets) external returns (bool , bytes memory) {
address adapter = _novaAdapters[stable];
require(
adapter != address(0),
Errors.NO_ADAPTER_APPROVED
);
(bool success, bytes memory data) = adapter.delegatecall(
abi.encodeWithSignature("deposit(uint256)", assets)
);
return (success, data)
}

function withdraw(address stable, uint256 shares) external returns (bool , bytes memory) {
address adapter = _novaAdapters[stable];
require(
adapter != address(0),
Errors.NO_ADAPTER_APPROVED
);
(bool success, bytes memory data) = adapter.delegatecall(
abi.encodeWithSignature("withdraw(uint256)", shares)
);
return (success, data)
}
}
10 changes: 10 additions & 0 deletions src/interfaces/INovaAdapterBase.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {ERC20} from "@solmate/tokens/ERC20.sol";

interface INovaAdapterBase {
function asset() external view returns (ERC20);
function deposit(uint256 assets) external returns (bool , uint256);
function withdraw(uint256 shares) external returns (bool, uint256);
}
6 changes: 6 additions & 0 deletions src/interfaces/INovaVault.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

interface INovaVault {
event ApprovedAdapter(address stable, address adapter);
}
11 changes: 11 additions & 0 deletions src/librairies/Errors.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;


library Errors {
string public constant INVALID_ADDRESS = "1";
string public constant ADAPTER_ALREADY_APPROVED = "2";
string public constant MISMATCHING_ARRAYS_LENGTH = "3";
string public constant INVALID_STABLE_TO_ADAPTER_MAPPING = "4";
string public constant NO_ADAPTER_APPROVED = "5";
}
Loading