Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include token transfer wrapper #391

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/SablierFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ contract SablierFlow is
_deposit(streamId, amount);
}

/// @inheritdoc ISablierFlow
function transferFrom(IERC20 token, address to, uint128 amount) external payable {
// Interaction: transfer the amount.
token.transferFrom({ from: msg.sender, to: to, value: amount });
}

/// @inheritdoc ISablierFlow
function void(uint256 streamId)
external
Expand Down
7 changes: 7 additions & 0 deletions src/interfaces/ISablierFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,13 @@ interface ISablierFlow is
/// @param amount The deposit amount, denoted in token's decimals.
function restartAndDeposit(uint256 streamId, UD21x18 ratePerSecond, uint128 amount) external payable;

/// @notice Transfers ERC-20 tokens from the caller to the `to` address.
/// @dev `msg.sender` must have approved this contract to spend the tokens.
/// @param token The contract address of the ERC-20 token to be transferred.
/// @param to The address receiving the tokens.
/// @param amount The amount of tokens to transfer, denoted in token's decimals.
function transferFrom(IERC20 token, address to, uint128 amount) external payable;

/// @notice Voids a stream.
///
/// @dev Emits {VoidFlowStream} event.
Expand Down
27 changes: 27 additions & 0 deletions tests/integration/fuzz/TransferFrom.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22;

import { Shared_Integration_Fuzz_Test } from "./Fuzz.t.sol";

contract TransferFrom_Integration_Fuzz_Test is Shared_Integration_Fuzz_Test {
function testFuzz_TransferFrom(address caller, address to, uint128 amount) external whenNoDelegateCall {
vm.assume(caller != address(0) && to != address(0) && caller != to);

// Change the caller and fund him with some tokens.
deal({ token: address(dai), to: caller, give: amount });
resetPrank(caller);

// Approve the flow contract to spend dai.
dai.approve(address(flow), amount);

uint256 beforeCallerBalance = dai.balanceOf(caller);
uint256 beforeToBalance = dai.balanceOf(to);

// Transfer amount to the provided address.
flow.transferFrom(dai, to, amount);

// It should update the balances.
assertEq(dai.balanceOf(caller), beforeCallerBalance - amount, "caller token balance");
assertEq(dai.balanceOf(to), beforeToBalance + amount, "recipient token balance");
}
}
Loading