Skip to content

Commit

Permalink
feat: add apr oracle and fix availableDepositLimit
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyonline committed Mar 9, 2024
1 parent 35b0f88 commit a07939e
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
26 changes: 23 additions & 3 deletions src/strategies/crvUSD/SiloLlamaAprOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@ pragma solidity 0.8.18;

import {AprOracleBase} from "@periphery/AprOracle/AprOracleBase.sol";

import {IInterestRateModel} from "@silo/interfaces/IInterestRateModel.sol";

Check warning on line 6 in src/strategies/crvUSD/SiloLlamaAprOracle.sol

View workflow job for this annotation

GitHub Actions / solidity

imported name IInterestRateModel is not used
import {ISiloRepository} from "@silo/interfaces/ISiloRepository.sol";
import {Solvency} from "@silo/lib/Solvency.sol";

Check warning on line 8 in src/strategies/crvUSD/SiloLlamaAprOracle.sol

View workflow job for this annotation

GitHub Actions / solidity

imported name Solvency is not used

contract SiloLlamaAprOracle is AprOracleBase {
constructor() AprOracleBase("Strategy Apr Oracle Example", msg.sender) {}

address private immutable silo;

Check warning on line 12 in src/strategies/crvUSD/SiloLlamaAprOracle.sol

View workflow job for this annotation

GitHub Actions / solidity

Immutable variables name are set to be in capitalized SNAKE_CASE
address private immutable asset;

Check warning on line 13 in src/strategies/crvUSD/SiloLlamaAprOracle.sol

View workflow job for this annotation

GitHub Actions / solidity

Immutable variables name are set to be in capitalized SNAKE_CASE

ISiloRepository private immutable siloRepository;

Check warning on line 15 in src/strategies/crvUSD/SiloLlamaAprOracle.sol

View workflow job for this annotation

GitHub Actions / solidity

Immutable variables name are set to be in capitalized SNAKE_CASE

constructor(address _siloRepository, address _silo, address _asset, string memory _name) AprOracleBase(_name, msg.sender) {
siloRepository = ISiloRepository(_siloRepository);

silo = _silo;
asset = _asset;
}

/**
* @notice Will return the expected Apr of a strategy post a debt change.
Expand All @@ -29,8 +44,13 @@ contract SiloLlamaAprOracle is AprOracleBase {
address _strategy,

Check warning on line 44 in src/strategies/crvUSD/SiloLlamaAprOracle.sol

View workflow job for this annotation

GitHub Actions / solidity

Variable "_strategy" is unused
int256 _delta

Check warning on line 45 in src/strategies/crvUSD/SiloLlamaAprOracle.sol

View workflow job for this annotation

GitHub Actions / solidity

Variable "_delta" is unused
) external view override returns (uint256) {
// TODO: Implement any necessary logic to return the most accurate
// APR estimation for the strategy.
// TODO -- + CRV/SILO rewards
// uint256 rateBeforeFee = IInterestRateModel(siloRepository.getInterestRateModel(silo, asset)).getCurrentInterestRate(
// silo,
// asset,
// block.timestamp
// );
// uint256 rateAfterFee = rateBeforeFee - (rateBeforeFee * siloRepository.protocolShareFee() / Solvency._PRECISION_DECIMALS);
return 1e17;
}
}
8 changes: 2 additions & 6 deletions src/strategies/crvUSD/SiloLlamaStrategy.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.18;

import {Math} from "@openzeppelin/contracts/utils/math/Math.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {BaseStrategy, ERC20} from "@tokenized-strategy/BaseStrategy.sol";
Expand Down Expand Up @@ -168,10 +167,7 @@ contract SiloLlamaStrategy is AuctionSwapper, BaseStrategy {
_claimAndSellRewards();

// Check how much we can re-deploy into the yield source.
uint256 toDeploy = Math.min(
asset.balanceOf(address(this)),
availableDepositLimit(address(this))
);
uint256 toDeploy = asset.balanceOf(address(this));

// If greater than 0.
if (toDeploy > 0) {
Expand Down Expand Up @@ -219,7 +215,7 @@ contract SiloLlamaStrategy is AuctionSwapper, BaseStrategy {
uint256, // _amountTaken
uint256 // _amountPayed
) internal override {
uint256 toDeploy = Math.min(asset.balanceOf(address(this)), availableDepositLimit(address(this)));
uint256 toDeploy = asset.balanceOf(address(this));
if (toDeploy > 0) _deployFunds(toDeploy);
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ pragma solidity ^0.8.18;
import "forge-std/console.sol";
import {Setup} from "./utils/Setup.sol";

import {StrategyAprOracle} from "../periphery/StrategyAprOracle.sol";
import {AprOracleBase} from "@periphery/AprOracle/AprOracleBase.sol";

contract OracleTest is Setup {
StrategyAprOracle public oracle;
AprOracleBase public oracle;

function setUp() public override {
super.setUp();
oracle = new StrategyAprOracle();
oracle = _deployAprOracle();
}

function checkOracle(address _strategy, uint256 _delta) public {
Expand Down
12 changes: 12 additions & 0 deletions src/test/utils/Strategies.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.18;

import {AprOracleBase} from "@periphery/AprOracle/AprOracleBase.sol";

import {ISilo} from "@silo/interfaces/ISilo.sol";

import {SiloLlamaStrategy} from "../../strategies/crvUSD/SiloLlamaStrategy.sol";
import {SiloLlamaAprOracle} from "../../strategies/crvUSD/SiloLlamaAprOracle.sol";

contract Strategies {

Expand All @@ -18,6 +21,15 @@ contract Strategies {
_earnSiloLlamaInterest();
}

function _deployAprOracle() internal returns (AprOracleBase) {
return AprOracleBase(address(new SiloLlamaAprOracle(
address(0xBCd67f35c7A2F212db0AD7f68fC773b5aC15377c), // _siloRepository
_crvUSDCRVSilo, // _silo
_crvUSD, // _asset
"crvUSD/CRV SiloLlamaAprOracle"
)));
}

function _setUpSiloLlamaStrategy() private returns (address _strategy) {
// address[] memory _rewardTokens,
address[] memory _rewardTokens = new address[](2);
Expand Down

0 comments on commit a07939e

Please sign in to comment.