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

fix: update resolver #132

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
241 changes: 128 additions & 113 deletions contracts/protocols/arbitrum/aave_v3/helpers.sol

Large diffs are not rendered by default.

132 changes: 59 additions & 73 deletions contracts/protocols/arbitrum/aave_v3/interfaces.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,15 @@ struct EModeCategory {
uint16 liquidationThreshold;
uint16 liquidationBonus;
// each eMode category may or may not have a custom oracle to override the individual assets price oracles
address priceSource;
string label;
uint128 isCollateralBitmap;
uint128 isBorrowableBitmap;
}

struct EModeCollateralConfig {
uint16 ltv;
uint16 liquidationThreshold;
uint16 liquidationBonus;
}

struct ReserveConfigurationMap {
Expand Down Expand Up @@ -146,13 +153,16 @@ struct AggregatedReserveData {
uint16 eModeLtv;
uint16 eModeLiquidationThreshold;
uint16 eModeLiquidationBonus;
address eModePriceSource;
uint128 isCollateralBitmap;
uint128 isBorrowableBitmap;
string eModeLabel;
bool borrowableInIsolation;
}

interface IPool {
function getUserAccountData(address user)
function getUserAccountData(
address user
)
external
view
returns (
Expand All @@ -164,12 +174,17 @@ interface IPool {
uint256 healthFactor
);

function getEModeCategoryData(uint8 id) external view returns (EModeCategory memory);
// 3.2 Updated Interface for eMode
function getEModeCategoryCollateralConfig(uint8 id) external view returns (EModeCollateralConfig memory);
function getEModeCategoryLabel(uint8 id) external view returns (string memory);
function getEModeCategoryCollateralBitmap(uint8 id) external view returns (uint128);
function getEModeCategoryBorrowableBitmap(uint8 id) external view returns (uint128);


//@return emode id of the user
function getUserEMode(address user) external view returns (uint256);

function getReservesList() external view virtual returns (address[] memory);
function getReservesList() external view returns (address[] memory);

function getUserConfiguration(address user) external view returns (UserConfigurationMap memory);

Expand Down Expand Up @@ -201,14 +216,7 @@ interface IAaveIncentivesController {

// @dev Returns the configuration of the distribution for a certain asset
// @return The asset index, the emission per second and the last updated timestamp
function assets(address asset)
external
view
returns (
uint128,
uint128,
uint256
);
function assets(address asset) external view returns (uint128, uint128, uint256);
}

interface IAaveOracle is IPriceOracleGetter {
Expand All @@ -235,7 +243,9 @@ interface IPoolAddressesProvider {

interface IPoolDataProvider {
// @notice Returns the reserve data
function getReserveData(address asset)
function getReserveData(
address asset
)
external
view
returns (
Expand Down Expand Up @@ -267,7 +277,9 @@ interface IStableDebtToken {
}

interface IAaveProtocolDataProvider is IPoolDataProvider {
function getReserveConfigurationData(address asset)
function getReserveConfigurationData(
address asset
)
external
view
returns (
Expand All @@ -287,8 +299,6 @@ interface IAaveProtocolDataProvider is IPoolDataProvider {

function getLiquidationProtocolFee(address asset) external view returns (uint256);

function getReserveEModeCategory(address asset) external view returns (uint256);

function getReserveCaps(address asset) external view returns (uint256 borrowCap, uint256 supplyCap);

// @notice Returns the debt ceiling of the reserve
Expand All @@ -299,7 +309,9 @@ interface IAaveProtocolDataProvider is IPoolDataProvider {

function getATokenTotalSupply(address asset) external view returns (uint256);

function getReserveData(address asset)
function getReserveData(
address asset
)
external
view
override
Expand All @@ -318,7 +330,10 @@ interface IAaveProtocolDataProvider is IPoolDataProvider {
uint40 lastUpdateTimestamp
);

function getUserReserveData(address asset, address user)
function getUserReserveData(
address asset,
address user
)
external
view
returns (
Expand All @@ -333,14 +348,9 @@ interface IAaveProtocolDataProvider is IPoolDataProvider {
bool usageAsCollateralEnabled
);

function getReserveTokensAddresses(address asset)
external
view
returns (
address aTokenAddress,
address stableDebtTokenAddress,
address variableDebtTokenAddress
);
function getReserveTokensAddresses(
address asset
) external view returns (address aTokenAddress, address stableDebtTokenAddress, address variableDebtTokenAddress);
}

//chainlink price feed
Expand All @@ -350,13 +360,7 @@ interface AggregatorV3Interface {
function latestRoundData()
external
view
returns (
uint80 roundId,
int256 answer,
uint256 startedAt,
uint256 updatedAt,
uint80 answeredInRound
);
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

function latestAnswer() external view returns (int256);
}
Expand All @@ -368,45 +372,32 @@ interface IERC20Detailed {
}

interface IUiIncentiveDataProviderV3 {
function getReservesIncentivesData(IPoolAddressesProvider provider)
external
view
returns (AggregatedReserveIncentiveData[] memory);
function getReservesIncentivesData(
IPoolAddressesProvider provider
) external view returns (AggregatedReserveIncentiveData[] memory);

function getUserReservesIncentivesData(IPoolAddressesProvider provider, address user)
external
view
returns (UserReserveIncentiveData[] memory);
function getUserReservesIncentivesData(
IPoolAddressesProvider provider,
address user
) external view returns (UserReserveIncentiveData[] memory);

// generic method with full data
function getFullReservesIncentiveData(IPoolAddressesProvider provider, address user)
external
view
returns (AggregatedReserveIncentiveData[] memory, UserReserveIncentiveData[] memory);
function getFullReservesIncentiveData(
IPoolAddressesProvider provider,
address user
) external view returns (AggregatedReserveIncentiveData[] memory, UserReserveIncentiveData[] memory);
}

interface IRewardsDistributor {
function getUserAssetData(
address user,
address asset,
address reward
) external view returns (uint256);
function getUserAssetData(address user, address asset, address reward) external view returns (uint256);

/**
* @dev Returns the configuration of the distribution for a certain asset
* @param asset The incentivized asset
* @param reward The reward token of the incentivized asset
* @return The asset index, the emission per second, the last updated timestamp and the distribution end timestamp
**/
function getRewardsData(address asset, address reward)
external
view
returns (
uint256,
uint256,
uint256,
uint256
);
function getRewardsData(address asset, address reward) external view returns (uint256, uint256, uint256, uint256);

/**
* @dev Returns the list of available reward token addresses of an incentivized asset
Expand Down Expand Up @@ -436,22 +427,18 @@ interface IRewardsDistributor {
* @param reward The address of the reward token
* @return The rewards amount
**/
function getUserRewards(
address[] calldata assets,
address user,
address reward
) external view returns (uint256);
function getUserRewards(address[] calldata assets, address user, address reward) external view returns (uint256);

/**
* @dev Returns a list all rewards of an user, including already accrued and unrealized claimable rewards
* @param assets List of incentivized assets to check eligible distributions
* @param user The address of the user
* @return The function returns a Tuple of rewards list and the unclaimed rewards list
**/
function getAllUserRewards(address[] calldata assets, address user)
external
view
returns (address[] memory, uint256[] memory);
function getAllUserRewards(
address[] calldata assets,
address user
) external view returns (address[] memory, uint256[] memory);

/**
* @dev Returns the decimals of an asset to calculate the distribution delta
Expand All @@ -473,8 +460,7 @@ interface IRewardsController is IRewardsDistributor {
}

interface IUiPoolDataProviderV3 {
function getReservesData(IPoolAddressesProvider provider)
external
view
returns (AggregatedReserveData[] memory, BaseCurrencyInfo memory);
function getReservesData(
IPoolAddressesProvider provider
) external view returns (AggregatedReserveData[] memory, BaseCurrencyInfo memory);
}
37 changes: 24 additions & 13 deletions contracts/protocols/arbitrum/aave_v3/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ contract AaveV3Resolver is AaveV3Helper {
*@return AaveV3TokenData details of tokens (e.g. symbol, decimals, ltv etc.).
*@return ReserveIncentiveData details of user's rewards corresponding to the tokens passed.
*/
function getPosition(address user, address[] memory tokens)
function getPosition(
address user,
address[] memory tokens,
address poolAddressProvider
)
public
view
returns (
Expand All @@ -35,18 +39,18 @@ contract AaveV3Resolver is AaveV3Helper {
_tokens[i] = tokens[i] == getEthAddr() ? getWethAddr() : tokens[i];
}

AaveV3UserData memory userDetails = getUserData(user);
AaveV3UserData memory userDetails = getUserData(user, poolAddressProvider);
// (TokenPrice[] memory tokenPrices, ) = getTokensPrices(userDetails.base.baseInUSD, _tokens);

AaveV3UserTokenData[] memory tokensData = new AaveV3UserTokenData[](length);
AaveV3TokenData[] memory collData = new AaveV3TokenData[](length);

for (uint256 i = 0; i < length; i++) {
tokensData[i] = getUserTokenData(user, _tokens[i]);
collData[i] = userCollateralData(_tokens[i]);
tokensData[i] = getUserTokenData(user, _tokens[i], poolAddressProvider);
collData[i] = userCollateralData(_tokens[i], poolAddressProvider);
}

return (userDetails, tokensData, collData, getIncentivesInfo(user));
return (userDetails, tokensData, collData, getIncentivesInfo(user, poolAddressProvider));
}

/**
Expand All @@ -58,7 +62,10 @@ contract AaveV3Resolver is AaveV3Helper {
*@return AaveV3TokenData details of tokens (e.g. symbol, decimals, ltv etc.).
*@return ReserveIncentiveData details of user's rewards corresponding to the tokens in the market.
*/
function getPositionAll(address user)
function getPositionAll(
address user,
address poolAddressProvider
)
public
view
returns (
Expand All @@ -68,7 +75,8 @@ contract AaveV3Resolver is AaveV3Helper {
ReserveIncentiveData[] memory
)
{
return getPosition(user, getList());
address[] memory tokens = getList(poolAddressProvider);
return getPosition(user, tokens, poolAddressProvider);
}

/**
Expand All @@ -78,9 +86,12 @@ contract AaveV3Resolver is AaveV3Helper {
*@return collateral array with an element as true if the corresponding token is used as collateral by the user, false otherwise.
*@return borrowed array with an element as true if the corresponding token is borrowed by the user, false otherwise.
*/
function getConfiguration(address user) public view returns (bool[] memory collateral, bool[] memory borrowed) {
uint256 data = getConfig(user).data;
address[] memory reserveIndex = getList();
function getConfiguration(
address user,
address poolAddressProvider
) public view returns (bool[] memory collateral, bool[] memory borrowed) {
uint256 data = getConfig(user, poolAddressProvider).data;
address[] memory reserveIndex = getList(poolAddressProvider);

collateral = new bool[](reserveIndex.length);
borrowed = new bool[](reserveIndex.length);
Expand All @@ -98,11 +109,11 @@ contract AaveV3Resolver is AaveV3Helper {
*@notice get list of all tokens available in the market.
*@return data array of token addresses available in the market.
*/
function getReservesList() public view returns (address[] memory data) {
data = getList();
function getReservesList(address poolAddressProvider) public view returns (address[] memory data) {
data = getList(poolAddressProvider);
}
}

contract InstaAaveV3ResolverArbitrum is AaveV3Resolver {
string public constant name = "AaveV3-Resolver-v1.0";
string public constant name = "AaveV3-Resolver-v1.1";
}
Loading