vault: _getAccount updates to the latest timestamp

This commit is contained in:
Mark Spanbroek 2025-02-04 15:01:16 +01:00
parent 2108f1265a
commit bdc721bfaa
2 changed files with 3 additions and 5 deletions

View File

@ -5,8 +5,8 @@ import "./Timestamps.sol";
import "./TokensPerSecond.sol";
struct Flow {
Timestamp start;
TokensPerSecond rate;
Timestamp updated;
}
library Flows {
@ -15,7 +15,7 @@ library Flows {
Timestamp timestamp
) internal pure returns (int128) {
int128 rate = TokensPerSecond.unwrap(flow.rate);
Timestamp start = flow.start;
Timestamp start = flow.updated;
Timestamp end = timestamp;
uint64 duration = Timestamp.unwrap(end) - Timestamp.unwrap(start);
return rate * int128(uint128(duration));

View File

@ -60,6 +60,7 @@ abstract contract VaultBase {
result.available -= uint128(-accumulated);
}
}
result.flow.updated = timestamp;
return result;
}
@ -173,10 +174,7 @@ abstract contract VaultBase {
Account memory senderAccount = _getAccount(controller, fund, from);
Account memory receiverAccount = _getAccount(controller, fund, to);
Timestamp start = Timestamps.currentTime();
senderAccount.flow.start = start;
senderAccount.flow.rate = senderAccount.flow.rate - rate;
receiverAccount.flow.start = start;
receiverAccount.flow.rate = receiverAccount.flow.rate + rate;
_checkAccountInvariant(senderAccount, lock);