diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 8d0b10a..9450646 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -26,7 +26,7 @@ jobs: - name: Compile and test contracts run: yarn compile && yarn test scenario-tests: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - name: Install Git diff --git a/contracts/partial/yToken/helpers.ligo b/contracts/partial/yToken/helpers.ligo index 2058fbb..41bbb7e 100644 --- a/contracts/partial/yToken/helpers.ligo +++ b/contracts/partial/yToken/helpers.ligo @@ -127,8 +127,7 @@ function calcMaxCollateralInCU( verifyInterestUpdated(token); (* sum += collateralFactorF * exchangeRate * oraclePrice * balance *) - acc := acc + userBalance * token.lastPrice - * token.collateralFactorF * liquidityF / token.totalSupplyF / precision; + acc := acc + userBalance * token.lastPrice * token.collateralFactorF * liquidityF / token.totalSupplyF / precision; } else skip; @@ -156,10 +155,10 @@ function calcLiquidateCollateral( verifyInterestUpdated(token); (* sum += balance * oraclePrice * exchangeRate *) - acc := acc + userBalance * token.lastPrice * liquidityF / token.totalSupplyF; + acc := acc + userBalance * token.lastPrice * token.threshold * liquidityF / token.totalSupplyF / precision; } else skip; - } with acc * token.threshold / precision; + } with acc; } with Set.fold(oneToken, userMarkets, 0n) function applyInterestToBorrows( diff --git a/integration_tests/test_quick.py b/integration_tests/test_quick.py index f301fea..663396a 100644 --- a/integration_tests/test_quick.py +++ b/integration_tests/test_quick.py @@ -1051,6 +1051,33 @@ def test_withraw_admin_rewards(self): with self.assertRaises(MichelsonRuntimeError): chain.execute(self.ct.withdrawReserve(1, 1), sender=admin) + def test_multicollateral_liquidate(self): + chain = LocalChain(storage=self.storage) + config = { + "collateral_factor": 0.5, + "reserve_factor": 0.5, + "price": 100, + "liquidity": INITIAL_LIQUIDITY, + "threshold": 0.5, + "reserve_liquidation_rate": 0.05, + } + self.add_token(chain, token_a, config) + self.add_token(chain, token_b, config) + self.add_token(chain, token_c, config) + + chain.execute(self.ct.mint(0, 100_000, 1)) + chain.execute(self.ct.mint(1, 100_000, 1)) + chain.execute(self.ct.enterMarket(0)) + chain.execute(self.ct.enterMarket(1)) + + with self.assertRaises(MichelsonRuntimeError): + chain.execute(self.ct.borrow(2, 100_001, chain.now + 2)) + + chain.execute(self.ct.borrow(2, 100_000, chain.now + 2)) + + with self.assertRaises(MichelsonRuntimeError): + chain.execute(self.ct.liquidate(2, 0, me, 1, 1, chain.now + 2), sender=bob) + def test_real_world_liquidation(self): price_a = 5244313 price_b = 56307584485