Skip to content

Commit

Permalink
Change moveIn interface to match transferFrom
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco <[email protected]>
  • Loading branch information
fulminmaxi committed Dec 23, 2024
1 parent e434c00 commit d04f11a
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/ITokenFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ interface ITokenFlow {
/// @notice Move tokens from the current flow payer into the specified address.
/// @dev Calling this function outside of a flow scope will revert.
/// @param token The token to move.
/// @param amount The amount of tokens to move.
/// @param to The address to move the tokens to.
function moveIn(address token, uint128 amount, address to) external;
/// @param amount The amount of tokens to move.
function moveIn(address token, address to, uint128 amount) external;

/// @notice A helper function to get the current flow payer.
function payer() external view returns (address);
Expand Down
2 changes: 1 addition & 1 deletion src/TokenFlow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract TokenFlow is ITokenFlow, ReentrancyGuardTransient {
}

/// @inheritdoc ITokenFlow
function moveIn(address token, uint128 amount, address to) external requireScope(INTERNAL_SCOPE) {
function moveIn(address token, address to, uint128 amount) external requireScope(INTERNAL_SCOPE) {
TransientNetflows.add(token, -int256(uint256(amount)));

token.safeTransferFrom(payer, to, amount);
Expand Down
2 changes: 1 addition & 1 deletion test/TokenFlow.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ contract TokenFlowTest is Test {

function test_revertCallingMoveInFromExternalScope() public {
vm.expectRevert(InvalidScope.selector);
tokenFlow.moveIn(address(token1), 1 ether, address(this));
tokenFlow.moveIn(address(token1), address(this), 1 ether);
}

function test_revertCallingMoveOutFromExternalScope() public {
Expand Down
41 changes: 5 additions & 36 deletions test/mocks/MockFlowScope.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {ITokenFlow} from "src/ITokenFlow.sol";

struct MoveIn {
address token;
address to;
uint128 amount;
address recipient;
}

struct MoveOut {
Expand Down Expand Up @@ -54,8 +54,8 @@ contract MockFlowScope is IFlowScope {
tokenFlow = _tokenFlow;
}

function addMoveIn(address token, uint128 amount, address recipient) external {
moveInInstructions.push(MoveIn({token: token, amount: amount, recipient: recipient}));
function addMoveIn(address token, uint128 amount, address to) external {
moveInInstructions.push(MoveIn({token: token, amount: amount, to: to}));
instructionTypes.push(InstructionType.MoveIn);
}

Expand Down Expand Up @@ -88,8 +88,8 @@ contract MockFlowScope is IFlowScope {
if (iType == InstructionType.MoveIn) {
tokenFlow.moveIn(
moveInInstructions[moveInIndex].token,
moveInInstructions[moveInIndex].amount,
moveInInstructions[moveInIndex].recipient
moveInInstructions[moveInIndex].to,
moveInInstructions[moveInIndex].amount
);
moveInIndex++;
} else if (iType == InstructionType.MoveOut) {
Expand All @@ -105,35 +105,4 @@ contract MockFlowScope is IFlowScope {
}
}
}

// function enter(
// bytes28, /* selectorExtension */
// Constraint[] calldata constraints,
// address, /* payer */
// bytes calldata /* data */
// ) external {
// // Execute all instructions
// for (uint256 i = 0; i < instructionTypes.length; i++) {
// InstructionType iType = instructionTypes[i];

// if (iType == InstructionType.MoveIn) {
// tokenFlow.moveIn(
// moveInInstructions[moveInIndex].token,
// moveInInstructions[moveInIndex].amount,
// moveInInstructions[moveInIndex].recipient
// );
// moveInIndex++;
// } else if (iType == InstructionType.MoveOut) {
// tokenFlow.moveOut(moveOutInstructions[moveOutIndex].token, moveOutInstructions[moveOutIndex].amount);
// moveOutIndex++;
// } else if (iType == InstructionType.Reentry) {
// ITokenFlow(msg.sender).main(
// constraints, reentryInstructions[reentryIndex].flowScope, reentryInstructions[reentryIndex].data
// );
// reentryIndex++;
// } else if (iType == InstructionType.Revert) {
// revert(revertInstructions[revertIndex].reason);
// }
// }
// }
}

0 comments on commit d04f11a

Please sign in to comment.