Skip to content

Commit

Permalink
DRY Updating Unresolved Payments
Browse files Browse the repository at this point in the history
  • Loading branch information
area authored and kronosapiens committed Aug 2, 2024
1 parent e07a66c commit 08d6b3a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
30 changes: 14 additions & 16 deletions contracts/extensions/StreamingPayments.sol
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,7 @@ contract StreamingPayments is ColonyExtensionMeta {
// Update 'claimed' as if we've had this rate since the beginning
streamingPayment.pseudoAmountClaimedFromStart = getAmountEntitledFromStart(_id);

bool isResolved = streamingPayment.pseudoAmountClaimedFromStart >=
getAmountClaimableLifetime(_id);

if (wasResolved && !isResolved) {
nUnresolvedStreamingPayments += 1;
} else if (!wasResolved && isResolved) {
nUnresolvedStreamingPayments -= 1;
}
updateUnresolvedPaymentCount(_id, wasResolved);

emit PaymentTokenUpdated(msgSender(), _id, _amount, _interval);
}
Expand Down Expand Up @@ -370,18 +363,11 @@ contract StreamingPayments is ColonyExtensionMeta {

streamingPayment.endTime = _endTime;

uint256 newLifetimeClaimable = getAmountClaimableLifetime(_id);

// Unlike when we're setting start time, we need to compare to pseudoAmountClaimedFromStart
// in order to determine if the payment is resolved or not.
bool wasResolved = streamingPayment.pseudoAmountClaimedFromStart >= oldLifetimeClaimable;
bool isResolved = streamingPayment.pseudoAmountClaimedFromStart >= newLifetimeClaimable;

if (wasResolved && !isResolved) {
nUnresolvedStreamingPayments += 1;
} else if (!wasResolved && isResolved) {
nUnresolvedStreamingPayments -= 1;
}
updateUnresolvedPaymentCount(_id, wasResolved);

emit EndTimeSet(msgSender(), _id, _endTime);
}
Expand Down Expand Up @@ -520,6 +506,18 @@ contract StreamingPayments is ColonyExtensionMeta {
return wmul(streamingPayment.amount, intervalsToClaimAsWad);
}

function updateUnresolvedPaymentCount(uint256 _id, bool wasResolved) internal {
StreamingPayment storage streamingPayment = streamingPayments[_id];
bool isResolved = streamingPayment.pseudoAmountClaimedFromStart >=
getAmountClaimableLifetime(_id);

if (wasResolved && !isResolved) {
nUnresolvedStreamingPayments += 1;
} else if (!wasResolved && isResolved) {
nUnresolvedStreamingPayments -= 1;
}
}

function setupExpenditure(
uint256 _permissionDomainId,
uint256 _childSkillIndex,
Expand Down
7 changes: 7 additions & 0 deletions docs/interfaces/extensions/streamingpayments.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ Update the token amount to be paid out. Claims existing payout prior to the chan
|_interval|uint256|The new interval over which _amount is paid out


### `uninstall()`

Called when uninstalling the extension




### `version():uint256 _version`

Returns the version of the extension
Expand Down

0 comments on commit 08d6b3a

Please sign in to comment.