generated from defi-wonderland/solidity-foundry-boilerplate
-
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.
chore: updated batchRequest constructor batching to fetch aave apy da…
…ta points
- Loading branch information
Showing
8 changed files
with
637 additions
and
54 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,48 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.23; | ||
|
||
import {Data, DataTypes, IIncentivesController, ILendingPool} from '../interfaces/aave-v2/IAaveV2.sol'; | ||
|
||
/** | ||
* To calculate deposit apy/apr from this data | ||
* https://docs.aave.com/developers/v/2.0/guides/apy-and-apr#compute-data | ||
*/ | ||
contract BatchAaveV2DataRequest { | ||
// This contract is used to fetch apy data points from aave | ||
constructor(ILendingPool _lendingPool, IIncentivesController _incentivesController, address[] memory _assets) { | ||
// create an array to store return data | ||
Data[] memory _returnData = new Data[](_assets.length); | ||
|
||
for (uint256 i = 0; i < _assets.length; i++) { | ||
DataTypes.ReserveData memory _reserveData = _lendingPool.getReserveData(_assets[i]); | ||
uint256 currentLiquidityRate = _reserveData.currentLiquidityRate; | ||
address aTokenAddress = _reserveData.aTokenAddress; | ||
|
||
// asset is the ERC20 supplied or borrowed, eg. DAI, WETH | ||
(, uint256 aEmissionPerSecond,) = _incentivesController.getAssetData(aTokenAddress); | ||
|
||
_returnData[i] = Data({ | ||
currentLiquidityRate: currentLiquidityRate, | ||
aTokenAddress: aTokenAddress, | ||
aEmissionPerSecond: aEmissionPerSecond | ||
}); | ||
} | ||
|
||
// encode return data | ||
bytes memory _data = abi.encode(_returnData); | ||
|
||
// force constructor to return data via assembly | ||
assembly { | ||
// abi.encode adds an additional offset (32 bytes) that we need to skip | ||
let _dataStart := add(_data, 32) | ||
// msize() gets the size of active memory in bytes. | ||
// if we subtract msize() from _dataStart, the output will be | ||
// the amount of bytes from _dataStart to the end of memory | ||
// which due to how the data has been laid out in memory, will coincide with | ||
// where our desired data ends. | ||
let _dataEnd := sub(msize(), _dataStart) | ||
// starting from _dataStart, get all the data in memory. | ||
return(_dataStart, _dataEnd) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,53 @@ | ||
// SPDX-License-Identifier: agpl-3.0 | ||
pragma solidity 0.8.23; | ||
|
||
library DataTypes { | ||
// refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties. | ||
struct ReserveData { | ||
//stores the reserve configuration | ||
ReserveConfigurationMap configuration; | ||
//the liquidity index. Expressed in ray | ||
uint128 liquidityIndex; | ||
//variable borrow index. Expressed in ray | ||
uint128 variableBorrowIndex; | ||
//the current supply rate. Expressed in ray | ||
uint128 currentLiquidityRate; | ||
//the current variable borrow rate. Expressed in ray | ||
uint128 currentVariableBorrowRate; | ||
//the current stable borrow rate. Expressed in ray | ||
uint128 currentStableBorrowRate; | ||
uint40 lastUpdateTimestamp; | ||
//tokens addresses | ||
address aTokenAddress; | ||
address stableDebtTokenAddress; | ||
address variableDebtTokenAddress; | ||
//address of the interest rate strategy | ||
address interestRateStrategyAddress; | ||
//the id of the reserve. Represents the position in the list of the active reserves | ||
uint8 id; | ||
} | ||
|
||
struct ReserveConfigurationMap { | ||
//bit 0-15: LTV | ||
//bit 16-31: Liq. threshold | ||
//bit 32-47: Liq. bonus | ||
//bit 48-55: Decimals | ||
//bit 56: Reserve is active | ||
//bit 57: reserve is frozen | ||
//bit 58: borrowing is enabled | ||
//bit 59: stable rate borrowing enabled | ||
//bit 60-63: reserved | ||
//bit 64-79: reserve factor | ||
uint256 data; | ||
} | ||
|
||
struct UserConfigurationMap { | ||
uint256 data; | ||
} | ||
|
||
enum InterestRateMode { | ||
NONE, | ||
STABLE, | ||
VARIABLE | ||
} | ||
} |
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,12 @@ | ||
// SPDX-License-Identifier: agpl-3.0 | ||
pragma solidity 0.8.23; | ||
|
||
import {DataTypes} from './DataTypes.sol'; | ||
import {IIncentivesController} from './IIncentivesController.sol'; | ||
import {ILendingPool} from './ILendingPool.sol'; | ||
|
||
struct Data { | ||
uint256 currentLiquidityRate; | ||
address aTokenAddress; | ||
uint256 aEmissionPerSecond; | ||
} |
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,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity >=0.7.0 <0.9.0; | ||
|
||
interface IIncentivesController { | ||
event AssetConfigUpdated(address indexed asset, uint256 emission); | ||
event AssetIndexUpdated(address indexed asset, uint256 index); | ||
event ClaimerSet(address indexed user, address indexed claimer); | ||
event DistributionEndUpdated(uint256 newDistributionEnd); | ||
event RewardsAccrued(address indexed user, uint256 amount); | ||
event RewardsClaimed(address indexed user, address indexed to, address indexed claimer, uint256 amount); | ||
event UserIndexUpdated(address indexed user, address indexed asset, uint256 index); | ||
|
||
function DISTRIBUTION_END() external view returns (uint256); | ||
|
||
function EMISSION_MANAGER() external view returns (address); | ||
|
||
function PRECISION() external view returns (uint8); | ||
|
||
function REVISION() external view returns (uint256); | ||
|
||
function REWARD_TOKEN() external view returns (address); | ||
|
||
function STAKE_TOKEN() external view returns (address); | ||
|
||
function assets(address) external view returns (uint104 emissionPerSecond, uint104 index, uint40 lastUpdateTimestamp); | ||
|
||
function claimRewards(address[] memory assets, uint256 amount, address to) external returns (uint256); | ||
|
||
function claimRewardsOnBehalf( | ||
address[] memory assets, | ||
uint256 amount, | ||
address user, | ||
address to | ||
) external returns (uint256); | ||
|
||
function claimRewardsToSelf(address[] memory assets, uint256 amount) external returns (uint256); | ||
|
||
function configureAssets(address[] memory assets, uint256[] memory emissionsPerSecond) external; | ||
|
||
function getAssetData(address asset) external view returns (uint256, uint256, uint256); | ||
|
||
function getClaimer(address user) external view returns (address); | ||
|
||
function getDistributionEnd() external view returns (uint256); | ||
|
||
function getRewardsBalance(address[] memory assets, address user) external view returns (uint256); | ||
|
||
function getUserAssetData(address user, address asset) external view returns (uint256); | ||
|
||
function getUserUnclaimedRewards(address _user) external view returns (uint256); | ||
|
||
function handleAction(address user, uint256 totalSupply, uint256 userBalance) external; | ||
|
||
function initialize(address) external; | ||
|
||
function setClaimer(address user, address caller) external; | ||
|
||
function setDistributionEnd(uint256 distributionEnd) external; | ||
} |
Oops, something went wrong.