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/v1 shortfalls #421

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions contracts/interfaces/IPoolParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ interface IPoolParameters {
*/
function setAuctionValidityTime(address user) external;

function repayForV1(
address[] calldata users,
address[] calldata assets,
uint256[] calldata amounts
) external;

/**
* @notice Returns the user account data across all the reserves
* @param user The address of the user
Expand Down
44 changes: 43 additions & 1 deletion contracts/protocol/pool/PoolParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {DataTypes} from "../libraries/types/DataTypes.sol";
import {IERC20WithPermit} from "../../interfaces/IERC20WithPermit.sol";
import {IPoolAddressesProvider} from "../../interfaces/IPoolAddressesProvider.sol";
import {IPoolParameters} from "../../interfaces/IPoolParameters.sol";
import {IPool} from "../../interfaces/IPool.sol";
import {INToken} from "../../interfaces/INToken.sol";
import {IPToken} from "../../interfaces/IPToken.sol";
import {IACLManager} from "../../interfaces/IACLManager.sol";
import {PoolStorage} from "./PoolStorage.sol";
import {FlashClaimLogic} from "../libraries/logic/FlashClaimLogic.sol";
Expand Down Expand Up @@ -52,6 +54,7 @@ contract PoolParameters is
uint256 internal constant POOL_REVISION = 200;
uint256 internal constant MAX_AUCTION_HEALTH_FACTOR = 3e18;
uint256 internal constant MIN_AUCTION_HEALTH_FACTOR = 1e18;
IPool internal immutable POOL_V1;
using SafeERC20 for IERC20;

/**
Expand Down Expand Up @@ -90,8 +93,9 @@ contract PoolParameters is
* @dev Constructor.
* @param provider The address of the PoolAddressesProvider contract
*/
constructor(IPoolAddressesProvider provider) {
constructor(IPoolAddressesProvider provider, IPool poolV1) {
ADDRESSES_PROVIDER = provider;
POOL_V1 = poolV1;
}

function getRevision() internal pure virtual override returns (uint256) {
Expand Down Expand Up @@ -286,6 +290,44 @@ contract PoolParameters is
ps._auctionRecoveryHealthFactor = value;
}

/// @inheritdoc IPoolParameters
function repayForV1(
address[] calldata users,
address[] calldata assets,
uint256[] calldata amounts
) external onlyPoolAdmin {
DataTypes.PoolStorage storage ps = poolStorage();
require(
users.length == assets.length && assets.length == amounts.length,
"invalid params"
);
for (uint256 i = 0; i < users.length; i++) {
DataTypes.ReserveData storage reserve = ps._reserves[assets[i]];
DataTypes.ReserveCache memory reserveCache = reserve.cache();

reserve.updateState(reserveCache);

reserve.updateInterestRates(reserveCache, assets[i], 0, amounts[i]);

DataTypes.TimeLockParams memory timeLockParams;
IPToken(reserveCache.xTokenAddress).transferUnderlyingTo(
address(this),
amounts[i],
timeLockParams
);
if (
IERC20(assets[i]).allowance(address(this), address(POOL_V1)) ==
0
) {
IERC20(assets[i]).safeApprove(
address(POOL_V1),
type(uint256).max
);
}
POOL_V1.repay(assets[i], amounts[i], users[i]);
}
}

/// @inheritdoc IPoolParameters
function getUserAccountData(
address user
Expand Down
4 changes: 2 additions & 2 deletions helpers/contracts-deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ export const deployPoolParameters = async (
const poolParameters = (await withSaveAndVerify(
await getContractFactory("PoolParameters", parametersLibraries),
eContractid.PoolParametersImpl,
[provider],
[provider, getParaSpaceConfig().ParaSpaceV1?.PoolV1 || ZERO_ADDRESS],
verify,
false,
parametersLibraries,
Expand Down Expand Up @@ -910,7 +910,7 @@ export const deployPoolComponents = async (
const poolParameters = (await withSaveAndVerify(
await getContractFactory("PoolParameters", parametersLibraries),
eContractid.PoolParametersImpl,
[provider],
[provider, getParaSpaceConfig().ParaSpaceV1?.PoolV1 || ZERO_ADDRESS],
verify,
false,
parametersLibraries,
Expand Down
20 changes: 20 additions & 0 deletions scripts/dev/1.ad-hoc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,27 @@
import rawBRE from "hardhat";
import {getPoolProxy} from "../../helpers/contracts-getters";
import {dryRunEncodedData} from "../../helpers/contracts-helpers";
import {upgradePoolParameters} from "../upgrade/pool";

const adHoc = async () => {
console.time("ad-hoc");
const pool = await getPoolProxy();
await upgradePoolParameters(
"0x9082ea82915fC507312d3daDeA4c921Edc4d4BAA",
false
);
const encodedData = pool.interface.encodeFunctionData("repayForV1", [
[
"0x10cda82ea4cd56d32c5a5e6dfcaa7af51d2ba350",
"0x0981f0e2b61575ff55074c76a539108bdc354148",
],
[
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
],
["82000000", "60000000"],
]);
await dryRunEncodedData(pool.address, encodedData);
console.timeEnd("ad-hoc");
};

Expand Down
Loading