From 96b4fc0effc1fc2706019a76c536af90aacb83e6 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 3 Mar 2025 11:55:28 +0100 Subject: [PATCH] vault: rename lock states - NoLock -> Inactive - Unlocked -> Withdrawing --- contracts/vault/Locks.sol | 35 +++++++++++++++++++---------------- contracts/vault/VaultBase.sol | 8 +++++--- test/Vault.tests.js | 8 ++++---- test/vault.js | 4 ++-- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/contracts/vault/Locks.sol b/contracts/vault/Locks.sol index 25efe89..298fd51 100644 --- a/contracts/vault/Locks.sol +++ b/contracts/vault/Locks.sol @@ -17,24 +17,27 @@ struct Lock { /// A lock can go through the following states: /// -/// ------------------------------------------ -/// | | -/// --> NoLock ---> Locked -----> UnLocked -- -/// \ ^ -/// \ / -/// --> Frozen -- +/// ----------------------------------------------- +/// | | +/// --> Inactive ---> Locked -----> Withdrawing -- +/// \ ^ +/// \ / +/// --> Frozen -- /// enum LockStatus { - /// Indicates that no lock is set. This is the initial state, or the state - /// after all tokens have been withdrawn. - NoLock, - /// Indicates that the fund is locked. Withdrawing tokens is not allowed. + /// Indicates that the fund is inactive and contains no tokens. This is the + /// initial state, or the state after all tokens have been withdrawn. + Inactive, + /// Indicates that a time-lock is set and withdrawing tokens is not allowed. A + /// fund needs to be locked for deposits, transfers, flows and burning to be + /// allowed. Locked, - /// Indicates that the fund is frozen. Flows have stopped, nothing is allowed - /// until the fund unlocks. + /// Indicates that a locked fund is frozen. Flows have stopped, nothing is + /// allowed until the fund unlocks. Frozen, - /// Indicates that the lock is unlocked. Withdrawing is allowed. - Unlocked + /// Indicates the fund has unlocked and withdrawing is allowed. Other + /// operations are no longer allowed. + Withdrawing } library Locks { @@ -46,9 +49,9 @@ library Locks { return LockStatus.Locked; } if (lock.maximum == Timestamp.wrap(0)) { - return LockStatus.NoLock; + return LockStatus.Inactive; } - return LockStatus.Unlocked; + return LockStatus.Withdrawing; } function flowEnd(Lock memory lock) internal pure returns (Timestamp) { diff --git a/contracts/vault/VaultBase.sol b/contracts/vault/VaultBase.sol index b3cfd25..ac2d603 100644 --- a/contracts/vault/VaultBase.sol +++ b/contracts/vault/VaultBase.sol @@ -85,7 +85,9 @@ abstract contract VaultBase { account.update(Timestamps.currentTime()); return account.balance; } - if (lockStatus == LockStatus.Unlocked || lockStatus == LockStatus.Frozen) { + if ( + lockStatus == LockStatus.Withdrawing || lockStatus == LockStatus.Frozen + ) { Account memory account = _accounts[controller][fundId][accountId]; account.update(lock.flowEnd()); return account.balance; @@ -100,7 +102,7 @@ abstract contract VaultBase { Timestamp maximum ) internal { Lock memory lock = _locks[controller][fundId]; - require(lock.status() == LockStatus.NoLock, VaultFundAlreadyLocked()); + require(lock.status() == LockStatus.Inactive, VaultFundAlreadyLocked()); lock.expiry = expiry; lock.maximum = maximum; _checkLockInvariant(lock); @@ -252,7 +254,7 @@ abstract contract VaultBase { AccountId accountId ) internal { Lock memory lock = _locks[controller][fundId]; - require(lock.status() == LockStatus.Unlocked, VaultFundNotUnlocked()); + require(lock.status() == LockStatus.Withdrawing, VaultFundNotUnlocked()); Account memory account = _accounts[controller][fundId][accountId]; account.update(lock.flowEnd()); diff --git a/test/Vault.tests.js b/test/Vault.tests.js index 6538fea..aa7ef89 100644 --- a/test/Vault.tests.js +++ b/test/Vault.tests.js @@ -679,7 +679,7 @@ describe("Vault", function () { expect(await vault.getLockStatus(fund)).to.equal(LockStatus.Locked) await expire() await mine() - expect(await vault.getLockStatus(fund)).to.equal(LockStatus.Unlocked) + expect(await vault.getLockStatus(fund)).to.equal(LockStatus.Withdrawing) }) describe("locking", function () { @@ -706,13 +706,13 @@ describe("Vault", function () { await expire() // some tokens are withdrawn await vault.withdraw(fund, account1) - expect(await vault.getLockStatus(fund)).to.equal(LockStatus.Unlocked) + expect(await vault.getLockStatus(fund)).to.equal(LockStatus.Withdrawing) expect(await vault.getLockExpiry(fund)).not.to.equal(0) // remainder of the tokens are withdrawn by recipient await vault .connect(holder3) .withdrawByRecipient(controller.address, fund, account3) - expect(await vault.getLockStatus(fund)).to.equal(LockStatus.NoLock) + expect(await vault.getLockStatus(fund)).to.equal(LockStatus.Inactive) expect(await vault.getLockExpiry(fund)).to.equal(0) }) }) @@ -946,7 +946,7 @@ describe("Vault", function () { it("unlocks when the lock expires", async function () { await advanceTimeTo(expiry) - expect(await vault.getLockStatus(fund)).to.equal(LockStatus.Unlocked) + expect(await vault.getLockStatus(fund)).to.equal(LockStatus.Withdrawing) }) testFundThatIsNotLocked() diff --git a/test/vault.js b/test/vault.js index 4b43dea..dc9885a 100644 --- a/test/vault.js +++ b/test/vault.js @@ -1,8 +1,8 @@ const LockStatus = { - NoLock: 0, + Inactive: 0, Locked: 1, Frozen: 2, - Unlocked: 3, + Withdrawing: 3, } module.exports = { LockStatus }