vault: rename lock states

- NoLock -> Inactive
- Unlocked -> Withdrawing
This commit is contained in:
Mark Spanbroek 2025-03-03 11:55:28 +01:00
parent 2900bed8fd
commit 96b4fc0eff
4 changed files with 30 additions and 25 deletions

View File

@ -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) {

View File

@ -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());

View File

@ -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()

View File

@ -1,8 +1,8 @@
const LockStatus = {
NoLock: 0,
Inactive: 0,
Locked: 1,
Frozen: 2,
Unlocked: 3,
Withdrawing: 3,
}
module.exports = { LockStatus }