Skip to content

Commit

Permalink
Merge branch 'test-cache' of github.com:mstable/mStable-contracts int…
Browse files Browse the repository at this point in the history
…o test-cache
  • Loading branch information
alsco77 committed Dec 23, 2020
2 parents a5d10ed + daf659a commit f796466
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
8 changes: 4 additions & 4 deletions contracts/masset/liquidator/Liquidator.sol
Expand Up @@ -7,7 +7,6 @@ import { ISavingsManager } from "../../interfaces/ISavingsManager.sol";
import { Initializable } from "@openzeppelin/upgrades/contracts/Initializable.sol";
import { InitializableModule } from "../../shared/InitializableModule.sol";
import { ILiquidator } from "./ILiquidator.sol";
import { MassetHelpers } from "../../masset/shared/MassetHelpers.sol";

import { IBasicToken } from "../../shared/IBasicToken.sol";
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";
Expand All @@ -20,8 +19,8 @@ import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
* @author Stability Labs Pty. Ltd.
* @notice The Liquidator allows rewards to be swapped for another token
* and returned to a calling contract
* @dev VERSION: 1.0
* DATE: 2020-10-13
* @dev VERSION: 1.2
* DATE: 2020-12-16
*/
contract Liquidator is
ILiquidator,
Expand All @@ -38,6 +37,7 @@ contract Liquidator is
address public mUSD;
ICurveMetaPool public curve;
IUniswapV2Router02 public uniswap;
// Deprecated var, but kept around to mirror storage layout
uint256 private interval = 7 days;

mapping(address => Liquidation) public liquidations;
Expand Down Expand Up @@ -217,7 +217,7 @@ contract Liquidator is
address bAsset = liquidation.bAsset;
require(bAsset != address(0), "Liquidation does not exist");

require(block.timestamp > liquidation.lastTriggered.add(interval), "Must wait for interval");
require(block.timestamp > liquidation.lastTriggered.add(7 days), "Must wait for interval");
liquidations[_integration].lastTriggered = block.timestamp;

// Cache variables
Expand Down
35 changes: 24 additions & 11 deletions test/masset/liquidator/TestLiquidatorContract.spec.ts
Expand Up @@ -3,7 +3,7 @@ import { StandardAccounts } from "@utils/machines";
import { simpleToExactAmount } from "@utils/math";
import { BN } from "@utils/tools";
import envSetup from "@utils/env_setup";
import { ZERO_ADDRESS, ONE_WEEK } from "@utils/constants";
import { ZERO_ADDRESS, ONE_WEEK, ONE_DAY } from "@utils/constants";
import * as t from "types/generated";

import shouldBehaveLikeModule from "../../shared/behaviours/Module.behaviour";
Expand All @@ -12,11 +12,13 @@ const MockTrigger = artifacts.require("MockTrigger");
const Liquidator = artifacts.require("Liquidator");
const MockCompoundIntegration = artifacts.require("MockCompoundIntegration1");
const SavingsManager = artifacts.require("SavingsManager");
const SavingsContract = artifacts.require("SavingsContract");
const MockERC20 = artifacts.require("MockERC20");
const MockMasset = artifacts.require("MockMasset");
const MockNexus = artifacts.require("MockNexus");
const MockCurve = artifacts.require("MockCurveMetaPool");
const MockUniswap = artifacts.require("MockUniswap");
const MockProxy = artifacts.require("MockProxy");

const { expect } = envSetup.configure();

Expand Down Expand Up @@ -98,9 +100,17 @@ contract("Liquidator", async (accounts) => {

// Add the module
// Liquidator
liquidator = await Liquidator.new();
await liquidator.initialize(nexus.address, uniswap.address, curve.address, mUSD.address);
savings = await SavingsManager.new(nexus.address, mUSD.address, sa.other, {
const proxy = await MockProxy.new();
const impl = await Liquidator.new();

const data: string = impl.contract.methods
.initialize(nexus.address, uniswap.address, curve.address, mUSD.address)
.encodeABI();
await proxy.methods["initialize(address,address,bytes)"](impl.address, sa.other, data);
liquidator = await Liquidator.at(proxy.address);

const save = await SavingsContract.new(nexus.address, mUSD.address);
savings = await SavingsManager.new(nexus.address, mUSD.address, save.address, {
from: sa.default,
});
await nexus.setSavingsManager(savings.address);
Expand Down Expand Up @@ -421,13 +431,6 @@ contract("Liquidator", async (accounts) => {
"Liquidation does not exist",
);
});
it("should fail if called within 7 days of the previous", async () => {
await liquidator.triggerLiquidation(compIntegration.address);
await expectRevert(
liquidator.triggerLiquidation(compIntegration.address),
"Must wait for interval",
);
});
it("should fail if Uniswap price is below the floor", async () => {
await uniswap.setRatio(69);
await expectRevert(
Expand Down Expand Up @@ -488,5 +491,15 @@ contract("Liquidator", async (accounts) => {
"Liquidation has been paused",
);
});
it("should fail if called within 7 days of the previous", async () => {
await liquidator.triggerLiquidation(compIntegration.address);
await time.increase(ONE_DAY.muln(5));
await expectRevert(
liquidator.triggerLiquidation(compIntegration.address),
"Must wait for interval",
);
await time.increase(ONE_DAY.muln(3));
await liquidator.triggerLiquidation(compIntegration.address);
});
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -4860,10 +4860,10 @@ inherits@2.0.3:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"
integrity sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=

ini@^1.3.5:
version "1.3.5"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.5.tgz#eee25f56db1c9ec6085e0c22778083f596abf927"
integrity sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==
ini@^1.3.4, ini@^1.3.5, ini@~1.3.0:
version "1.3.8"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==

inquirer@^7.0.0:
version "7.3.3"
Expand Down

0 comments on commit f796466

Please sign in to comment.