Skip to content

Commit

Permalink
consistency in variable naming
Browse files Browse the repository at this point in the history
  • Loading branch information
smol-ninja committed Oct 15, 2024
1 parent 06afe8a commit 8793cf1
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/SablierFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ contract SablierFlow is
}

/// @notice Calculates the total debt.
/// @dev The total debt is the sum of the snapshot debt and the ongoing debt. This value is independent of the
/// stream's balance.
/// @dev The total debt is the sum of the snapshot debt and the ongoing debt descaled to token's decimal. This
/// value is independent of the stream's balance.
function _totalDebtOf(uint256 streamId) internal view returns (uint256) {
uint256 scaledTotalDebt = _ongoingDebtScaledOf(streamId) + _streams[streamId].snapshotDebtScaled;
return Helpers.descaleAmount({ amount: scaledTotalDebt, decimals: _streams[streamId].tokenDecimals });
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/ISablierFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ interface ISablierFlow is
/// @param streamId The stream ID for the query.
function depletionTimeOf(uint256 streamId) external view returns (uint256 depletionTime);

/// @notice Returns the amount of debt accrued since the snapshot time until now, denoted in token's decimals.
/// @notice Returns the amount of debt accrued since the snapshot time until now, denoted as a fixed-point number
/// where 1e18 is 1 token.
/// @dev Reverts if `streamId` references a null stream.
/// @param streamId The stream ID for the query.
function ongoingDebtScaledOf(uint256 streamId) external view returns (uint256 ongoingDebtScaled);
Expand Down
6 changes: 3 additions & 3 deletions tests/fork/Flow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ contract Flow_Fork_Test is Fork_Test {
flow.adjustRatePerSecond({ streamId: streamId, newRatePerSecond: newRatePerSecond });

// It should update snapshot debt.
vars.actualSnapshotDebt = flow.getSnapshotDebtScaled(streamId);
vars.expectedSnapshotDebt = ongoingDebtScaled + beforeSnapshotAmount;
assertEq(vars.actualSnapshotDebt, vars.expectedSnapshotDebt, "AdjustRatePerSecond: snapshot debt");
vars.actualScaledSnapshotDebt = flow.getSnapshotDebtScaled(streamId);
vars.expectedScaledSnapshotDebt = ongoingDebtScaled + beforeSnapshotAmount;
assertEq(vars.actualScaledSnapshotDebt, vars.expectedScaledSnapshotDebt, "AdjustRatePerSecond: snapshot debt");

// It should set the new rate per second
vars.actualRatePerSecond = flow.getRatePerSecond(streamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ contract AdjustRatePerSecond_Integration_Concrete_Test is Integration_Test {
uint40 expectedSnapshotTime = getBlockTimestamp() - ONE_MONTH;
assertEq(actualSnapshotTime, expectedSnapshotTime, "snapshot time");

uint256 actualSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
uint128 expectedSnapshotDebt = 0;
assertEq(actualSnapshotDebt, expectedSnapshotDebt, "snapshot debt");
uint256 actualScaledSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
uint128 expectedScaledSnapshotDebt = 0;
assertEq(actualScaledSnapshotDebt, expectedScaledSnapshotDebt, "snapshot debt");

UD21x18 newRatePerSecond = ud21x18(RATE_PER_SECOND.unwrap() / 2);

Expand All @@ -118,9 +118,9 @@ contract AdjustRatePerSecond_Integration_Concrete_Test is Integration_Test {
assertEq(uint8(flow.statusOf(defaultStreamId)), uint8(Flow.Status.STREAMING_SOLVENT), "status not streaming");

// It should update snapshot debt.
actualSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
expectedSnapshotDebt = ONE_MONTH_DEBT_18D;
assertEq(actualSnapshotDebt, expectedSnapshotDebt, "snapshot debt");
actualScaledSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
expectedScaledSnapshotDebt = ONE_MONTH_DEBT_18D;
assertEq(actualScaledSnapshotDebt, expectedScaledSnapshotDebt, "snapshot debt");

// It should set the new rate per second
actualRatePerSecond = flow.getRatePerSecond(defaultStreamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract DepositAndPause_Integration_Concrete_Test is Integration_Test {

function test_WhenCallerSender() external whenNoDelegateCall givenNotNull givenNotPaused {
uint128 previousStreamBalance = flow.getBalance(defaultStreamId);
uint256 expectedSnapshotDebt = flow.ongoingDebtScaledOf(defaultStreamId);
uint256 expectedScaledSnapshotDebt = flow.ongoingDebtScaledOf(defaultStreamId);

// It should emit 1 {Transfer}, 1 {DepositFlowStream}, 1 {PauseFlowStream}, 1 {MetadataUpdate} events
vm.expectEmit({ emitter: address(usdc) });
Expand Down Expand Up @@ -98,7 +98,7 @@ contract DepositAndPause_Integration_Concrete_Test is Integration_Test {
assertEq(actualRatePerSecond, 0, "rate per second");

// It should update the snapshot debt
uint256 actualSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
assertEq(actualSnapshotDebt, expectedSnapshotDebt, "snapshot debt");
uint256 actualScaledSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
assertEq(actualScaledSnapshotDebt, expectedScaledSnapshotDebt, "snapshot debt");
}
}
6 changes: 3 additions & 3 deletions tests/integration/concrete/pause/pause.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ contract Pause_Integration_Concrete_Test is Integration_Test {
}

function _test_Pause() private {
uint256 expectedSnapshotDebt = flow.ongoingDebtScaledOf(defaultStreamId);
uint256 expectedScaledSnapshotDebt = flow.ongoingDebtScaledOf(defaultStreamId);

// It should emit 1 {PauseFlowStream}, 1 {MetadataUpdate} events.
vm.expectEmit({ emitter: address(flow) });
Expand All @@ -90,7 +90,7 @@ contract Pause_Integration_Concrete_Test is Integration_Test {
assertEq(actualRatePerSecond, 0, "rate per second");

// It should update the snapshot debt.
uint256 actualSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
assertEq(actualSnapshotDebt, expectedSnapshotDebt, "snapshot debt");
uint256 actualScaledSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
assertEq(actualScaledSnapshotDebt, expectedScaledSnapshotDebt, "snapshot debt");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ contract RefundAndPause_Integration_Concrete_Test is Integration_Test {
}

function test_WhenCallerSender() external whenNoDelegateCall givenNotNull givenNotPaused {
uint256 expectedSnapshotDebt = flow.ongoingDebtScaledOf(defaultStreamId);
uint256 expectedScaledSnapshotDebt = flow.ongoingDebtScaledOf(defaultStreamId);

// It should emit 1 {Transfer}, 1 {RefundFromFlowStream}, 1 {PauseFlowStream}, 1 {MetadataUpdate} events
vm.expectEmit({ emitter: address(usdc) });
Expand Down Expand Up @@ -96,7 +96,7 @@ contract RefundAndPause_Integration_Concrete_Test is Integration_Test {
assertEq(actualRatePerSecond, 0, "rate per second");

// It should update the snapshot debt
uint256 actualSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
assertEq(actualSnapshotDebt, expectedSnapshotDebt, "snapshot debt");
uint256 actualScaledSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
assertEq(actualScaledSnapshotDebt, expectedScaledSnapshotDebt, "snapshot debt");
}
}
4 changes: 2 additions & 2 deletions tests/integration/concrete/withdraw-max/withdrawMax.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ contract WithdrawMax_Integration_Concrete_Test is Integration_Test {
assertEq(vars.actualStreamBalance, vars.expectedStreamBalance, "stream balance");

// It should set the snapshot debt to zero.
vars.actualSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
assertEq(vars.actualSnapshotDebt, 0, "snapshot debt");
vars.actualScaledSnapshotDebt = flow.getSnapshotDebtScaled(defaultStreamId);
assertEq(vars.actualScaledSnapshotDebt, 0, "snapshot debt");

if (flow.getRatePerSecond(defaultStreamId).unwrap() > 0) {
// It should update snapshot time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ contract OngoingDebtScaledOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Te
// Pause the stream.
flow.pause(streamId);

uint256 expectedOngoingDebtScaled = flow.ongoingDebtScaledOf(streamId);
uint256 expectedScaledOngoingDebt = flow.ongoingDebtScaledOf(streamId);

// Simulate the passage of time after pause.
vm.warp({ newTimestamp: getBlockTimestamp() + timeJump });

// Assert that the ongoing debt did not change.
uint256 actualOngoingDebtScaled = flow.ongoingDebtScaledOf(streamId);
assertEq(actualOngoingDebtScaled, expectedOngoingDebtScaled, "ongoing debt");
uint256 actualScaledOngoingDebt = flow.ongoingDebtScaledOf(streamId);
assertEq(actualScaledOngoingDebt, expectedScaledOngoingDebt, "ongoing debt");
}

/// @dev It should return 0.
Expand Down Expand Up @@ -56,8 +56,8 @@ contract OngoingDebtScaledOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Te
updateSnapshotTimeAndWarp(streamId);

// Assert that ongoing debt is zero.
uint256 actualOngoingDebtScaled = flow.ongoingDebtScaledOf(streamId);
assertEq(actualOngoingDebtScaled, 0, "ongoing debt");
uint256 actualScaledOngoingDebt = flow.ongoingDebtScaledOf(streamId);
assertEq(actualScaledOngoingDebt, 0, "ongoing debt");
}

/// @dev It should return the ongoing debt.
Expand Down Expand Up @@ -88,8 +88,8 @@ contract OngoingDebtScaledOf_Integration_Fuzz_Test is Shared_Integration_Fuzz_Te
uint128 ratePerSecond = flow.getRatePerSecond(streamId).unwrap();

// Assert that the ongoing debt equals the expected value.
uint256 actualOngoingDebtScaled = flow.ongoingDebtScaledOf(streamId);
uint256 expectedOngoingDebtScaled = ratePerSecond * timeJump;
assertEq(actualOngoingDebtScaled, expectedOngoingDebtScaled, "ongoing debt");
uint256 actualScaledOngoingDebt = flow.ongoingDebtScaledOf(streamId);
uint256 expectedScaledOngoingDebt = ratePerSecond * timeJump;
assertEq(actualScaledOngoingDebt, expectedScaledOngoingDebt, "ongoing debt");
}
}
4 changes: 2 additions & 2 deletions tests/integration/fuzz/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ contract Withdraw_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test {

vars.previousAggregateAmount = flow.aggregateBalance(token);
vars.previousTokenBalance = token.balanceOf(address(flow));
vars.previousOngoingDebtScaled = flow.totalDebtOf(streamId);
vars.previousScaledOngoingDebt = flow.totalDebtOf(streamId);
vars.previousTotalDebt = getDescaledAmount(
flow.getSnapshotDebtScaled(streamId), flow.getTokenDecimals(streamId)
) + vars.previousOngoingDebtScaled;
) + vars.previousScaledOngoingDebt;
vars.previousStreamBalance = flow.getBalance(streamId);

vars.expectedProtocolRevenue = flow.protocolRevenue(token);
Expand Down
6 changes: 3 additions & 3 deletions tests/utils/Vars.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ struct Vars {
IERC20 token;
// previous values.
uint256 previousAggregateAmount;
uint256 previousOngoingDebtScaled;
uint256 previousScaledOngoingDebt;
uint40 previousSnapshotTime;
uint128 previousStreamBalance;
uint256 previousTokenBalance;
Expand All @@ -20,7 +20,7 @@ struct Vars {
uint128 actualProtocolFeeAmount;
uint128 actualProtocolRevenue;
UD21x18 actualRatePerSecond;
uint256 actualSnapshotDebt;
uint256 actualScaledSnapshotDebt;
uint40 actualSnapshotTime;
uint128 actualStreamBalance;
uint256 actualStreamId;
Expand All @@ -32,7 +32,7 @@ struct Vars {
uint128 expectedProtocolFeeAmount;
uint128 expectedProtocolRevenue;
UD21x18 expectedRatePerSecond;
uint256 expectedSnapshotDebt;
uint256 expectedScaledSnapshotDebt;
uint40 expectedSnapshotTime;
uint128 expectedStreamBalance;
uint256 expectedStreamId;
Expand Down

0 comments on commit 8793cf1

Please sign in to comment.