-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17e30a2
commit 052bfd7
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
uint256[] calldata novaAdapters | ||
) { | ||
_approveNovaAdapters(stables, novaAdapters); | ||
} | ||
|
||
function _approveNovaAdapters( | ||
address[] calldata stables, | ||
address[] calldata novaAdapters, | ||
) internal { | ||
require( | ||
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 addapter = _novaAdapters[stable]; | ||
require( | ||
addapter != address(0), | ||
Errors.NO_ADAPTER_APPROVED | ||
); | ||
(bool success, bytes memory data) = adapter.delegatecall( | ||
abi.encodeWithSignature("deposit(uint256)", assets) | ||
); | ||
return (sucess, data) | ||
} | ||
|
||
function withdraw(address stable, uint256 shares) external returns (bool , bytes memory) { | ||
address addapter = _novaAdapters[stable]; | ||
require( | ||
addapter != address(0), | ||
Errors.NO_ADAPTER_APPROVED | ||
); | ||
(bool success, bytes memory data) = adapter.delegatecall( | ||
abi.encodeWithSignature("withdraw(uint256)", shares) | ||
); | ||
return (sucess, data) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
interface INovaAdapterBase { | ||
ERC20 asset; | ||
|
||
function deposit(uint256 assets) external returns (bool , uint256); | ||
|
||
function withdraw(uint256 shares) external returns (bool, uint256); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, uint256 adapter; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// SPDX-License-Identifier: agpl-3.0 | ||
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"; | ||
} |