diff --git a/contracts/vault/VaultBase.sol b/contracts/vault/VaultBase.sol index 2bed0ec..e40f630 100644 --- a/contracts/vault/VaultBase.sol +++ b/contracts/vault/VaultBase.sol @@ -69,7 +69,7 @@ abstract contract VaultBase { Timestamp maximum ) internal { Lock memory lock = _locks[controller][fund]; - require(lock.maximum == Timestamp.wrap(0), AlreadyLocked()); + require(lock.status() == LockStatus.NoLock, FundAlreadyLocked()); lock.expiry = expiry; lock.maximum = maximum; _checkLockInvariant(lock); @@ -82,7 +82,7 @@ abstract contract VaultBase { Timestamp expiry ) internal { Lock memory lock = _locks[controller][fund]; - require(lock.status() == LockStatus.Locked, LockRequired()); + require(lock.status() == LockStatus.Locked, FundNotLocked()); require(lock.expiry <= expiry, InvalidExpiry()); lock.expiry = expiry; _checkLockInvariant(lock); @@ -96,7 +96,7 @@ abstract contract VaultBase { uint128 amount ) internal { Lock storage lock = _locks[controller][fund]; - require(lock.status() == LockStatus.Locked, LockRequired()); + require(lock.status() == LockStatus.Locked, FundNotLocked()); Account storage account = _accounts[controller][fund][recipient]; @@ -117,7 +117,7 @@ abstract contract VaultBase { uint128 amount ) internal { Lock memory lock = _locks[controller][fund]; - require(lock.status() == LockStatus.Locked, LockRequired()); + require(lock.status() == LockStatus.Locked, FundNotLocked()); Account memory account = _accounts[controller][fund][recipient]; require(amount <= account.balance.available, InsufficientBalance()); @@ -137,7 +137,7 @@ abstract contract VaultBase { uint128 amount ) internal { Lock memory lock = _locks[controller][fund]; - require(lock.status() == LockStatus.Locked, LockRequired()); + require(lock.status() == LockStatus.Locked, FundNotLocked()); Account memory sender = _accounts[controller][fund][from]; require(amount <= sender.balance.available, InsufficientBalance()); @@ -158,7 +158,7 @@ abstract contract VaultBase { TokensPerSecond rate ) internal { Lock memory lock = _locks[controller][fund]; - require(lock.status() == LockStatus.Locked, LockRequired()); + require(lock.status() == LockStatus.Locked, FundNotLocked()); Account memory sender = _accounts[controller][fund][from]; sender.flowOut(rate); @@ -176,7 +176,7 @@ abstract contract VaultBase { Recipient recipient ) internal { Lock storage lock = _locks[controller][fund]; - require(lock.status() == LockStatus.Locked, LockRequired()); + require(lock.status() == LockStatus.Locked, FundNotLocked()); Account memory account = _accounts[controller][fund][recipient]; require(account.flow.incoming == account.flow.outgoing, FlowMustBeZero()); @@ -191,7 +191,7 @@ abstract contract VaultBase { function _burnAll(Controller controller, Fund fund) internal { Lock storage lock = _locks[controller][fund]; - require(lock.status() == LockStatus.Locked, LockRequired()); + require(lock.status() == LockStatus.Locked, FundNotLocked()); lock.burned = true; @@ -204,7 +204,7 @@ abstract contract VaultBase { Recipient recipient ) internal { Lock memory lock = _locks[controller][fund]; - require(lock.status() == LockStatus.Unlocked, Locked()); + require(lock.status() == LockStatus.Unlocked, FundNotUnlocked()); Account memory account = _accounts[controller][fund][recipient]; account.update(lock.expiry); @@ -224,7 +224,7 @@ abstract contract VaultBase { } function _checkLockInvariant(Lock memory lock) private pure { - require(lock.expiry <= lock.maximum, ExpiryPastMaximum()); + require(lock.expiry <= lock.maximum, InvalidExpiry()); } function _checkAccountInvariant( @@ -235,10 +235,9 @@ abstract contract VaultBase { } error InsufficientBalance(); - error Locked(); - error AlreadyLocked(); - error ExpiryPastMaximum(); error InvalidExpiry(); - error LockRequired(); + error FundNotLocked(); + error FundNotUnlocked(); + error FundAlreadyLocked(); error FlowMustBeZero(); } diff --git a/test/Vault.tests.js b/test/Vault.tests.js index 3a18606..dc3762d 100644 --- a/test/Vault.tests.js +++ b/test/Vault.tests.js @@ -53,7 +53,7 @@ describe("Vault", function () { it("does not allow a lock with expiry past maximum", async function () { let maximum = (await currentTime()) + 100 const locking = vault.lock(fund, maximum + 1, maximum) - await expect(locking).to.be.revertedWith("ExpiryPastMaximum") + await expect(locking).to.be.revertedWith("InvalidExpiry") }) describe("fund is not locked", function () { @@ -94,7 +94,7 @@ describe("Vault", function () { it("cannot extend a lock past its maximum", async function () { const extending = vault.extendLock(fund, maximum + 1) - await expect(extending).to.be.revertedWith("ExpiryPastMaximum") + await expect(extending).to.be.revertedWith("InvalidExpiry") }) it("cannot move expiry forward", async function () { @@ -535,7 +535,7 @@ describe("Vault", function () { it("does not allow withdrawal before lock expires", async function () { await setNextBlockTimestamp(expiry - 1) const withdrawing = vault.withdraw(fund, account.address) - await expect(withdrawing).to.be.revertedWith("Locked") + await expect(withdrawing).to.be.revertedWith("FundNotUnlocked") }) it("disallows withdrawal for everyone in the fund", async function () { @@ -544,8 +544,8 @@ describe("Vault", function () { await vault.transfer(fund, address1, address2, amount / 2) let withdrawing1 = vault.withdraw(fund, address1) let withdrawing2 = vault.withdraw(fund, address2) - await expect(withdrawing1).to.be.revertedWith("Locked") - await expect(withdrawing2).to.be.revertedWith("Locked") + await expect(withdrawing1).to.be.revertedWith("FundNotUnlocked") + await expect(withdrawing2).to.be.revertedWith("FundNotUnlocked") }) }) }) @@ -778,12 +778,12 @@ describe("Vault", function () { function testBurnedFund() { it("cannot set lock", async function () { const locking = vault.lock(fund, expiry, maximum) - await expect(locking).to.be.revertedWith("AlreadyLocked") + await expect(locking).to.be.revertedWith("FundAlreadyLocked") }) it("cannot withdraw", async function () { const withdrawing = vault.withdraw(fund, account.address) - await expect(withdrawing).to.be.revertedWith("Locked") + await expect(withdrawing).to.be.revertedWith("FundNotUnlocked") }) testFundThatIsNotLocked() @@ -794,7 +794,7 @@ describe("Vault", function () { it("does not allow extending of lock", async function () { await expect( vault.extendLock(fund, (await currentTime()) + 1) - ).to.be.revertedWith("LockRequired") + ).to.be.revertedWith("FundNotLocked") }) it("does not allow depositing of tokens", async function () { @@ -802,35 +802,35 @@ describe("Vault", function () { await token.connect(controller).approve(vault.address, amount) await expect( vault.deposit(fund, account.address, amount) - ).to.be.revertedWith("LockRequired") + ).to.be.revertedWith("FundNotLocked") }) it("does not allow designating tokens", async function () { await expect( vault.designate(fund, account.address, 0) - ).to.be.revertedWith("LockRequired") + ).to.be.revertedWith("FundNotLocked") }) it("does not allow transfer of tokens", async function () { await expect( vault.transfer(fund, account.address, account2.address, 0) - ).to.be.revertedWith("LockRequired") + ).to.be.revertedWith("FundNotLocked") }) it("does not allow new token flows to start", async function () { await expect( vault.flow(fund, account.address, account2.address, 0) - ).to.be.revertedWith("LockRequired") + ).to.be.revertedWith("FundNotLocked") }) it("does not allow burning of accounts", async function () { await expect(vault.burn(fund, account.address)).to.be.revertedWith( - "LockRequired" + "FundNotLocked" ) }) it("does not allow burning an entire fund", async function () { - await expect(vault.burnAll(fund)).to.be.revertedWith("LockRequired") + await expect(vault.burnAll(fund)).to.be.revertedWith("FundNotLocked") }) } })