-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
silo strategy initial implementation
- Loading branch information
1 parent
be267d7
commit 6892f32
Showing
7 changed files
with
157 additions
and
5 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
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
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,117 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import "./base/ERC4626StrategyBase.sol"; | ||
import "./libs/StrategyIdLib.sol"; | ||
import "../integrations/silo/ISiloIncentivesController.sol"; | ||
import "../integrations/silo/ISilo.sol"; | ||
|
||
/// @title Earns APR by lending assets on Silo V2 | ||
/// @author 0xhokugava (https://github.com/0xhokugava) | ||
contract SiloStrategy is ERC4626StrategyBase { | ||
using SafeERC20 for IERC20; | ||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* CONSTANTS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @inheritdoc IControllable | ||
string public constant VERSION = "1.0.0"; | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* INITIALIZATION */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @inheritdoc IStrategy | ||
function initialize(address[] memory addresses, uint[] memory nums, int24[] memory ticks) public initializer { | ||
if (addresses.length != 3 || nums.length != 0 || ticks.length != 0) { | ||
revert IControllable.IncorrectInitParams(); | ||
} | ||
__ERC4626StrategyBase_init(StrategyIdLib.SILO, addresses[0], addresses[1], addresses[2]); | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* VIEW FUNCTIONS */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @inheritdoc IStrategy | ||
function strategyLogicId() public pure override returns (string memory) { | ||
return StrategyIdLib.SILO; | ||
} | ||
|
||
/// @inheritdoc IStrategy | ||
function extra() external pure returns (bytes32) { | ||
return CommonLib.bytesToBytes32(abi.encodePacked(bytes3(0x00d395), bytes3(0x000000))); | ||
} | ||
Check warning Code scanning / Slither Too many digits Warning
SiloStrategy.extra() uses literals with too many digits:
- CommonLib.bytesToBytes32(abi.encodePacked(bytes3(0x00d395),bytes3(0x000000))) |
||
|
||
/// @inheritdoc IStrategy | ||
function description() external view returns (string memory) { | ||
StrategyBaseStorage storage $base = _getStrategyBaseStorage(); | ||
return _genDesc($base._underlying); | ||
} | ||
|
||
/// @inheritdoc IStrategy | ||
function getSpecificName() external pure override returns (string memory, bool) { | ||
return ("", false); | ||
} | ||
|
||
/// @inheritdoc IStrategy | ||
function supportedVaultTypes() external pure override returns (string[] memory types) { | ||
types = new string[](1); | ||
types[0] = VaultTypeLib.COMPOUNDING; | ||
} | ||
|
||
/// @inheritdoc IStrategy | ||
function initVariants(address platform_) | ||
public | ||
view | ||
returns (string[] memory variants, address[] memory addresses, uint[] memory nums, int24[] memory ticks) | ||
{} | ||
|
||
/// @inheritdoc IStrategy | ||
function isHardWorkOnDepositAllowed() external pure returns (bool) { | ||
return true; | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* STRATEGY BASE */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
/// @inheritdoc ERC4626StrategyBase | ||
//slither-disable-next-line unused-return | ||
function _depositAssets(uint[] memory amounts, bool) internal override returns (uint value) { | ||
StrategyBaseStorage storage $base = _getStrategyBaseStorage(); | ||
address u = $base._underlying; | ||
ERC4626StrategyBaseStorage storage $ = _getERC4626StrategyBaseStorage(); | ||
if ($.lastSharePrice == 0) { | ||
$.lastSharePrice = _getSharePrice(u); | ||
} | ||
ISilo siloVault = ISilo(u); | ||
value = siloVault.deposit(amounts[0], address(this), ISilo.CollateralType.Collateral); | ||
} | ||
|
||
/// @inheritdoc ERC4626StrategyBase | ||
//slither-disable-next-line unused-return | ||
function _withdrawAssets( | ||
address[] memory, | ||
uint value, | ||
address receiver | ||
) internal virtual override returns (uint[] memory amountsOut) { | ||
amountsOut = new uint[](1); | ||
StrategyBaseStorage storage $base = _getStrategyBaseStorage(); | ||
amountsOut[0] = ISilo($base._underlying).withdraw(value, receiver, address(this), ISilo.CollateralType.Collateral); | ||
} | ||
|
||
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/ | ||
/* INTERNAL LOGIC */ | ||
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/ | ||
|
||
function _genDesc(address silo) internal view returns (string memory) { | ||
return string.concat( | ||
"Earn ", | ||
// CommonLib.implode(CommonLib.getSymbols(silo), ", "), | ||
" and supply APR by lending ", | ||
IERC20Metadata(ISilo(silo).asset()).symbol(), | ||
" to Silo V2" | ||
); | ||
} | ||
} |
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
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
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
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,27 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import "../base/chains/SonicSetup.sol"; | ||
import "../base/UniversalTest.sol"; | ||
|
||
contract SiloStrategyTest is SonicSetup, UniversalTest { | ||
constructor() { | ||
vm.selectFork(vm.createFork(vm.envString("SONIC_RPC_URL"))); | ||
vm.rollFork(6548098); // Feb-04-2025 03:31:56 PM +UTC | ||
} | ||
|
||
function testSiFSonic() public universalTest { | ||
_addStrategy(SonicLib.SILO_VAULT_USDC_20); | ||
} | ||
|
||
function _addStrategy(address siloVault) internal { | ||
strategies.push( | ||
Strategy({ | ||
id: StrategyIdLib.SILO, | ||
pool: address(0), | ||
farmId: type(uint).max, | ||
underlying: siloVault | ||
}) | ||
); | ||
} | ||
} |