From 896dc935395b1af930fbd991b8c9a914507ab169 Mon Sep 17 00:00:00 2001 From: GopherJ Date: Sat, 30 Sep 2023 15:49:40 +0800 Subject: [PATCH 1/3] fix: v1 shortfalls Signed-off-by: GopherJ --- contracts/interfaces/IPoolParameters.sol | 6 +++ contracts/protocol/pool/PoolParameters.sol | 44 +++++++++++++++++++++- helpers/contracts-deployments.ts | 4 +- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/contracts/interfaces/IPoolParameters.sol b/contracts/interfaces/IPoolParameters.sol index aa8691ee..ac47e2e2 100644 --- a/contracts/interfaces/IPoolParameters.sol +++ b/contracts/interfaces/IPoolParameters.sol @@ -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 diff --git a/contracts/protocol/pool/PoolParameters.sol b/contracts/protocol/pool/PoolParameters.sol index 4a8d53cb..683bb463 100644 --- a/contracts/protocol/pool/PoolParameters.sol +++ b/contracts/protocol/pool/PoolParameters.sol @@ -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"; @@ -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; /** @@ -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) { @@ -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 diff --git a/helpers/contracts-deployments.ts b/helpers/contracts-deployments.ts index 25a9ac4f..ca20cc8b 100644 --- a/helpers/contracts-deployments.ts +++ b/helpers/contracts-deployments.ts @@ -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, @@ -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, From 20a0328ae0cc88a324654a4b320c478d09c61e8f Mon Sep 17 00:00:00 2001 From: GopherJ Date: Sat, 30 Sep 2023 15:54:23 +0800 Subject: [PATCH 2/3] chore: add script Signed-off-by: GopherJ --- scripts/dev/1.ad-hoc.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/scripts/dev/1.ad-hoc.ts b/scripts/dev/1.ad-hoc.ts index 9da115af..1b12057e 100644 --- a/scripts/dev/1.ad-hoc.ts +++ b/scripts/dev/1.ad-hoc.ts @@ -1,7 +1,22 @@ import rawBRE from "hardhat"; +import {getPoolProxy} from "../../helpers/contracts-getters"; +import {dryRunEncodedData} from "../../helpers/contracts-helpers"; const adHoc = async () => { console.time("ad-hoc"); + const pool = await getPoolProxy(); + const encodedData = pool.interface.encodeFunctionData("repayForV1", [ + [ + "0x10cda82ea4cd56d32c5a5e6dfcaa7af51d2ba350", + "0x0981f0e2b61575ff55074c76a539108bdc354148", + ], + [ + "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", + "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599", + ], + ["82000000", "60000000"], + ]); + await dryRunEncodedData(pool.address, encodedData); console.timeEnd("ad-hoc"); }; From 18c2aabc2fa6327b64d3d5c2c2cf1484199fc44e Mon Sep 17 00:00:00 2001 From: GopherJ Date: Sat, 30 Sep 2023 15:58:03 +0800 Subject: [PATCH 3/3] chore: upgrade parameters first Signed-off-by: GopherJ --- scripts/dev/1.ad-hoc.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/dev/1.ad-hoc.ts b/scripts/dev/1.ad-hoc.ts index 1b12057e..a280dc75 100644 --- a/scripts/dev/1.ad-hoc.ts +++ b/scripts/dev/1.ad-hoc.ts @@ -1,10 +1,15 @@ 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",