Skip to content

Commit

Permalink
Add some basic cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alsco77 committed Jan 10, 2021
1 parent 92c4fed commit e6d2dfe
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
7 changes: 4 additions & 3 deletions contracts/savings/SavingsContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,8 @@ contract SavingsContract is
}

// 3. Level the assets to Fraction (connector) & 100-fraction (raw)
uint256 realSum = _data.rawBalance.add(connectorBalance);
uint256 ideal = realSum.mulTruncate(_data.fraction);
uint256 sum = _data.rawBalance.add(connectorBalance);
uint256 ideal = sum.mulTruncate(_data.fraction);
// If there is not enough mAsset in the connector, then deposit
if(ideal > connectorBalance){
uint256 deposit = ideal.sub(connectorBalance);
Expand All @@ -563,6 +563,7 @@ contract SavingsContract is
// If fraction == 0, then withdraw everything
if(ideal == 0){
connector_.withdrawAll();
sum = IERC20(underlying).balanceOf(address(this));
} else {
connector_.withdraw(connectorBalance.sub(ideal));
}
Expand All @@ -571,7 +572,7 @@ contract SavingsContract is

// 4i. Refresh exchange rate and emit event
lastBalance = ideal;
_refreshExchangeRate(realSum, _data.totalCredits, false);
_refreshExchangeRate(sum, _data.totalCredits, false);
emit Poked(lastBalance_, ideal, connectorBalance.sub(lastBalance_));

} else {
Expand Down
63 changes: 56 additions & 7 deletions test/savings/TestSavingsContract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,25 +1059,74 @@ contract("SavingsContract", async (accounts) => {
});

describe("poking", () => {
it("allows only poker to poke");
it("fails if there are no credits");
it("should fail if the raw balance goes down somehow", async () => {
// _refreshExchangeRate
// ExchangeRate must increase
const deposit = simpleToExactAmount(100, 18);
before(async () => {
await createNewSavingsContract();
});
it("allows only poker to poke", async () => {
await expectRevert(
savingsContract.poke({ from: sa.governor }),
"Only poker can execute",
);
});
it("fails if there are no credits", async () => {
const credits = await savingsContract.totalSupply();
expect(credits).bignumber.eq(new BN(0));
await expectRevert(
savingsContract.poke({ from: sa.default }),
"Must have something to poke",
);
});
it("only allows pokes once every 4h", async () => {
await masset.approve(savingsContract.address, simpleToExactAmount(1, 21));
await savingsContract.preDeposit(deposit, alice);
await savingsContract.poke();
await time.increase(ONE_HOUR.muln(3));
await expectRevert(
savingsContract.poke({ from: sa.default }),
"Not enough time elapsed",
);
});
it("only allows pokes once every 4h");
context("with a connector", () => {
beforeEach(async () => {
await createNewSavingsContract();
const connector = await MockConnector.new(savingsContract.address, masset.address);

await masset.approve(savingsContract.address, simpleToExactAmount(1, 21));
await savingsContract.preDeposit(deposit, alice);

await savingsContract.setConnector(connector.address, { from: sa.governor });
});
afterEach(async () => {
const data = await getData(savingsContract, alice);
expect(exchangeRateHolds(data), "Exchange rate must hold");
});
it("should do nothing if the fraction is 0");
it("should fail if the raw balance goes down somehow", async () => {
// _refreshExchangeRate
// ExchangeRate must increase
});
it("should accrue interest and update exchange rate", async () => {
// check everything - lastPoke, lastBalance, etc
});
it("should fail if the APY is too high");
it("should fail if the APY is too high", async () => {
// in 30 mins: "Interest protected from inflating past 10 Bps"
// > 30 mins: "Interest protected from inflating past maxAPY"
});
it("should fail if the balance has gone down", async () => {
// "Invalid yield"
});
it("should deposit to the connector if total supply lowers", async () => {
// deposit 1
// increase total balance
// deposit 2
});
it("should withdraw from the connector if total supply lowers");

// For ex. in yVault and due to slippage on Curve (+ price movement)
context("handling unavailable assets in the connector", () => {
it("does x");
});
});
context("with no connector", () => {
it("simply updates the exchangeRate using the raw balance");
Expand Down

0 comments on commit e6d2dfe

Please sign in to comment.