vault: simplify _getAccount()

This commit is contained in:
Mark Spanbroek 2025-02-04 15:04:19 +01:00
parent bdc721bfaa
commit 16f853b5d8

View File

@ -39,29 +39,20 @@ abstract contract VaultBase {
Fund fund, Fund fund,
Recipient recipient Recipient recipient
) internal view returns (Account memory) { ) internal view returns (Account memory) {
Account storage account = _accounts[controller][fund][recipient]; Account memory account = _accounts[controller][fund][recipient];
Lock storage lock = _locks[controller][fund];
Timestamp timestamp = Timestamps.currentTime(); Timestamp timestamp = Timestamps.currentTime();
return _getAccountAt(account, lock, timestamp);
}
function _getAccountAt(
Account memory account,
Lock storage lock,
Timestamp timestamp
) private view returns (Account memory) {
Account memory result = account;
if (account.flow.rate != TokensPerSecond.wrap(0)) { if (account.flow.rate != TokensPerSecond.wrap(0)) {
Lock memory lock = _locks[controller][fund];
Timestamp end = Timestamps.earliest(timestamp, lock.expiry); Timestamp end = Timestamps.earliest(timestamp, lock.expiry);
int128 accumulated = account.flow._totalAt(end); int128 accumulated = account.flow._totalAt(end);
if (accumulated >= 0) { if (accumulated >= 0) {
result.designated += uint128(accumulated); account.designated += uint128(accumulated);
} else { } else {
result.available -= uint128(-accumulated); account.available -= uint128(-accumulated);
} }
} }
result.flow.updated = timestamp; account.flow.updated = timestamp;
return result; return account;
} }
function _getLock( function _getLock(