Skip to content

Commit

Permalink
Merge branch 'hrikb/weeth-merged' into jun/multisig-actions
Browse files Browse the repository at this point in the history
  • Loading branch information
HrikB committed Feb 21, 2024
2 parents 47a8f24 + 0f2cdf6 commit 1929b2b
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 253 deletions.
13 changes: 6 additions & 7 deletions deploy-sim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,22 +65,21 @@ ionpool_addr=$(jq '.returns.ionPool.value' "broadcast/04_DeployIonPool.s.sol/$ch
spot_oracle=$(jq '.returns.spotOracle.value' "broadcast/05_DeployInitialReserveAndSpotOracles.s.sol/$chain_id/run-latest.json" | xargs)

jq --arg ionpool_addr "$ionpool_addr" --arg spot_oracle "$spot_oracle" '. + { "ionPool": $ionpool_addr, "spotOracle": $spot_oracle }' deployment-config/06_SetupCollateral.json >temp.json && mv temp.json deployment-config/06_SetupCollateral.json
# jq --arg ionpool_addr "$ionpool_addr" --arg wst_eth_spot "$wst_eth_spot" --arg ethx_spot "$ethx_spot" --arg sw_eth_spot "$sw_eth_spot" '. + { "ionPool": $ionpool_addr, "wstEthSpot": $wst_eth_spot, "ethXSpot": $ethx_spot, "swEthSpot": $sw_eth_spot }' deployment-config/06_SetupInitialCollaterals.json >temp.json && mv temp.json deployment-config/06_SetupInitialCollaterals.json

# Setup initial collaterals
bun run 06_SetupCollateral:deployment:deploy:$chain_name --broadcast

jq --arg ionpool_addr "$ionpool_addr" '. + { "ionPool": $ionpool_addr }' deployment-config/07_DeployInitialGemJoins.json >temp.json && mv temp.json deployment-config/07_DeployInitialGemJoins.json
jq --arg ionpool_addr "$ionpool_addr" '. + { "ionPool": $ionpool_addr }' deployment-config/07_DeployGemJoin.json >temp.json && mv temp.json deployment-config/07_DeployGemJoin.json

# Deploy GemJoins
bun run 07_DeployInitialGemJoins:deployment:deploy:$chain_name --broadcast
bun run 07_DeployGemJoin:deployment:deploy:$chain_name --broadcast

gem_join_addr=$(jq '.returns.gemJoin.value' "broadcast/07_DeployInitialGemJoins.s.sol/$chain_id/run-latest.json" | xargs)
gem_join_addr=$(jq '.returns.gemJoin.value' "broadcast/07_DeployGemJoin.s.sol/$chain_id/run-latest.json" | xargs)

jq --arg ionpool_addr "$ionpool_addr" --arg gem_join "$gem_join_addr" --arg whitelist "$whitelist_addr" '. + { "ionPool": $ionpool_addr, "gemJoin": $gem_join, whitelist: $whitelist }' deployment-config/08_DeployInitialHandlers.json >temp.json && mv temp.json deployment-config/08_DeployInitialHandlers.json
jq --arg ionpool_addr "$ionpool_addr" --arg gem_join "$gem_join_addr" --arg whitelist "$whitelist_addr" '. + { "ionPool": $ionpool_addr, "gemJoin": $gem_join, whitelist: $whitelist }' deployment-config/08_DeployHandlers.json >temp.json && mv temp.json deployment-config/08_DeployHandlers.json

# Deploy Handlers
bun run 08_DeployInitialHandlers:deployment:deploy:$chain_name --broadcast
bun run 08_DeployHandlers:deployment:deploy:$chain_name --broadcast

# Deploy Liquidation
echo "DEPLOYING LIQUIDATION..."
Expand All @@ -95,7 +94,7 @@ bun run 09_DeployLiquidation:deployment:deploy:$chain_name --broadcast
# AdminTransfer and tests

# write all the deployed addresses to json
weeth_handler_addr=$(jq '.returns.handler.value' "broadcast/08_DeployInitialHandlers.s.sol/$chain_id/run-latest.json" | xargs)
weeth_handler_addr=$(jq '.returns.handler.value' "broadcast/08_DeployHandlers.s.sol/$chain_id/run-latest.json" | xargs)
liquidation=$(jq '.returns.liquidation.value' "broadcast/09_DeployLiquidation.s.sol/$chain_id/run-latest.json" | xargs)

echo "{
Expand Down
2 changes: 1 addition & 1 deletion slither.db.json

Large diffs are not rendered by default.

59 changes: 16 additions & 43 deletions src/Liquidation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,76 +72,49 @@ contract Liquidation {
* @param _ionPool The address of the `IonPool` contract.
* @param _protocol The address that will represent the protocol balance
* sheet (for protocol liquidation purposes).
* @param _reserveOracles List of reserve oracle addresses for each ilk.
* @param _liquidationThresholds List of liquidation thresholds for each
* ilk.
* @param _reserveOracle Reserve oracle for the ilk.
* @param _liquidationThreshold Liquidation threshold for the ilk.
* @param _targetHealth The target health ratio for positions.
* @param _reserveFactor Base discount for collateral.
* @param _maxDiscounts List of max discounts for each ilk.
* @param _maxDiscount Max discount for the ilk.
*/
constructor(
address _ionPool,
address _protocol,
address[] memory _reserveOracles,
uint256[] memory _liquidationThresholds,
address _reserveOracle,
uint256 _liquidationThreshold,
uint256 _targetHealth,
uint256 _reserveFactor,
uint256[] memory _maxDiscounts
uint256 _maxDiscount
) {
IonPool ionPool_ = IonPool(_ionPool);
POOL = ionPool_;
PROTOCOL = _protocol;

uint256 ilkCount = POOL.ilkCount();
if (_maxDiscount >= RAY) revert InvalidMaxDiscount(_maxDiscount);

uint256 maxDiscountsLength = _maxDiscounts.length;
if (maxDiscountsLength != ilkCount) {
revert InvalidMaxDiscountsLength(_maxDiscounts.length);
}

if (_reserveOracles.length != ilkCount) {
revert InvalidReserveOraclesLength(_reserveOracles.length);
}

uint256 liquidationThresholdsLength = _liquidationThresholds.length;
if (liquidationThresholdsLength != ilkCount) {
revert InvalidLiquidationThresholdsLength(_liquidationThresholds.length);
}

for (uint256 i = 0; i < maxDiscountsLength;) {
if (_maxDiscounts[i] >= RAY) revert InvalidMaxDiscount(_maxDiscounts[i]);

// forgefmt: disable-next-line
unchecked { ++i; }
}

for (uint256 i = 0; i < liquidationThresholdsLength;) {
if (_liquidationThresholds[i] == 0) revert InvalidLiquidationThreshold(_liquidationThresholds[i]);

// This invariant must hold otherwise all liquidations will revert
// when discount == configs.maxDiscount within the _getRepayAmt
// function.
if (_targetHealth < _liquidationThresholds[i].rayDivUp(RAY - _maxDiscounts[i])) {
revert InvalidTargetHealth(_targetHealth);
}
if (_liquidationThreshold == 0) revert InvalidLiquidationThreshold(_liquidationThreshold);

// forgefmt: disable-next-line
unchecked { ++i; }
// This invariant must hold otherwise all liquidations will revert
// when discount == configs.maxDiscount within the _getRepayAmt
// function.
if (_targetHealth < _liquidationThreshold.rayDivUp(RAY - _maxDiscount)) {
revert InvalidTargetHealth(_targetHealth);
}

if (_targetHealth < RAY) revert InvalidTargetHealth(_targetHealth);

TARGET_HEALTH = _targetHealth;
BASE_DISCOUNT = _reserveFactor;
MAX_DISCOUNT = _maxDiscounts[0];
MAX_DISCOUNT = _maxDiscount;

IERC20 underlying = ionPool_.underlying();
underlying.approve(address(ionPool_), type(uint256).max); // approve ionPool to transfer the UNDERLYING asset
UNDERLYING = underlying;

LIQUIDATION_THRESHOLD = _liquidationThresholds[0];
LIQUIDATION_THRESHOLD = _liquidationThreshold;

RESERVE_ORACLE = _reserveOracles[0];
RESERVE_ORACLE = _reserveOracle;
}

struct Configs {
Expand Down
Loading

0 comments on commit 1929b2b

Please sign in to comment.