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: shortfalls using treasury #419

Closed
wants to merge 14 commits into from
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ zksync-bytecode-hashes:
redeploy-market:
make SCRIPT_PATH=./scripts/dev/15.redeploy-market.ts run

.PHONY: fix-shortfalls
fix-shortfalls:
make SCRIPT_PATH=./scripts/dev/16.fix-shortfalls.ts run

.PHONY: transfer-tokens
transfer-tokens:
make SCRIPT_PATH=./scripts/dev/2.transfer-tokens.ts run
Expand Down
11 changes: 11 additions & 0 deletions contracts/interfaces/IPoolParameters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ interface IPoolParameters {
**/
function mintToTreasury(address[] calldata assets) external;

/**
* @notice Fix shortfalls by sending reserves to xTokens
* @param assets The list of reserves for which the minting needs to be executed
**/
function fixShortfalls(
address[] calldata assets,
address[] calldata shortfallUsers,
address[] calldata shortfallAssets,
uint256[] calldata shortfallAmounts
) external;

/**
* @notice Rescue and transfer tokens locked in this contract
* @param assetType The asset type of the token
Expand Down
8 changes: 8 additions & 0 deletions contracts/interfaces/IWstETH.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

interface IWstETH {
function wrap(uint256 _stETHAmount) external returns (uint256);

function unwrap(uint256 _wstETHAmount) external returns (uint256);
}
18 changes: 10 additions & 8 deletions contracts/protocol/libraries/logic/SupplyLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ library SupplyLogic {
reserve.updateState(reserveCache);

uint256 userBalance = IPToken(reserveCache.xTokenAddress)
.scaledBalanceOf(msg.sender)
.scaledBalanceOf(params.from)
.rayMul(reserveCache.nextLiquidityIndex);

uint256 amountToWithdraw = params.amount;
Expand All @@ -340,19 +340,21 @@ library SupplyLogic {
amountToWithdraw
);

DataTypes.TimeLockParams memory timeLockParams = GenericLogic
.calculateTimeLockParams(
DataTypes.TimeLockParams memory timeLockParams;
if (!params.immediate) {
timeLockParams = GenericLogic.calculateTimeLockParams(
reserve,
DataTypes.TimeLockFactorParams({
assetType: DataTypes.AssetType.ERC20,
asset: params.asset,
amount: amountToWithdraw
})
);
timeLockParams.actionType = DataTypes.TimeLockActionType.WITHDRAW;
timeLockParams.actionType = DataTypes.TimeLockActionType.WITHDRAW;
}

IPToken(reserveCache.xTokenAddress).burn(
msg.sender,
params.from,
params.to,
amountToWithdraw,
reserveCache.nextLiquidityIndex,
Expand All @@ -366,19 +368,19 @@ library SupplyLogic {
reservesList,
userConfig,
params.asset,
msg.sender,
params.from,
params.reservesCount,
params.oracle
);
}

if (amountToWithdraw == userBalance) {
userConfig.setUsingAsCollateral(reserve.id, false);
emit ReserveUsedAsCollateralDisabled(params.asset, msg.sender);
emit ReserveUsedAsCollateralDisabled(params.asset, params.from);
}
}

emit Withdraw(params.asset, msg.sender, params.to, amountToWithdraw);
emit Withdraw(params.asset, params.from, params.to, amountToWithdraw);

return amountToWithdraw;
}
Expand Down
2 changes: 2 additions & 0 deletions contracts/protocol/libraries/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,11 @@ library DataTypes {
struct ExecuteWithdrawParams {
address asset;
uint256 amount;
address from;
address to;
uint256 reservesCount;
address oracle;
bool immediate;
}

struct ExecuteWithdrawERC721Params {
Expand Down
4 changes: 3 additions & 1 deletion contracts/protocol/pool/PoolCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,11 @@ contract PoolCore is
DataTypes.ExecuteWithdrawParams({
asset: asset,
amount: amount,
from: msg.sender,
to: to,
reservesCount: ps._reservesCount,
oracle: ADDRESSES_PROVIDER.getPriceOracle()
oracle: ADDRESSES_PROVIDER.getPriceOracle(),
immediate: false
})
);
}
Expand Down
Loading
Loading