Skip to content

Commit

Permalink
refactor: remove unnecessary min and rename claim_amount
Browse files Browse the repository at this point in the history
  • Loading branch information
fubuloubu committed Sep 6, 2024
1 parent 3c88b3d commit 56b2e7b
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions contracts/StreamManager.vy
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,12 @@ def cancel_stream(
assert self.streams[creator][stream_id].start_time + MIN_STREAM_LIFE <= block.timestamp

funded_amount: uint256 = self.streams[creator][stream_id].funded_amount
amount_locked: uint256 = funded_amount - self._amount_unlocked(creator, stream_id)
amount_locked: uint256 = funded_amount - self._amount_unlocked(creator, stream_id)
self.streams[creator][stream_id].funded_amount = funded_amount - amount_locked

token: ERC20 = self.streams[creator][stream_id].token
assert token.transfer(creator, amount_locked, default_return_value=True)

self.streams[creator][stream_id].funded_amount = funded_amount - amount_locked

log StreamCancelled(creator, stream_id, amount_locked, reason)

return funded_amount - amount_locked
Expand All @@ -238,17 +237,13 @@ def cancel_stream(
@external
def claim(creator: address, stream_id: uint256) -> uint256:
funded_amount: uint256 = self.streams[creator][stream_id].funded_amount
claimed_amount: uint256 = min(
self._amount_unlocked(creator, stream_id),
funded_amount,
)
claim_amount: uint256 = self._amount_unlocked(creator, stream_id)
self.streams[creator][stream_id].funded_amount = funded_amount - claim_amount
self.streams[creator][stream_id].last_pull = block.timestamp

token: ERC20 = self.streams[creator][stream_id].token
assert token.transfer(self.owner, claimed_amount, default_return_value=True)

self.streams[creator][stream_id].funded_amount = funded_amount - claimed_amount
self.streams[creator][stream_id].last_pull = block.timestamp
assert token.transfer(self.owner, claim_amount, default_return_value=True)

log Claimed(creator, stream_id, funded_amount == claimed_amount, claimed_amount)
log Claimed(creator, stream_id, funded_amount == claim_amount, claim_amount)

return claimed_amount
return claim_amount

0 comments on commit 56b2e7b

Please sign in to comment.