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

implement safe transfer from as in the todo for the example #108

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 3 additions & 1 deletion contracts/hooks/examples/FullRange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {FixedPoint96} from "@uniswap/v4-core/src/libraries/FixedPoint96.sol";
import {FixedPointMathLib} from "solmate/utils/FixedPointMathLib.sol";
import {IERC20Metadata} from "@openzeppelin/contracts/interfaces/IERC20Metadata.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "../../libraries/LiquidityAmounts.sol";

Expand Down Expand Up @@ -264,7 +266,7 @@ contract FullRange is BaseHook, ILockCallback {
if (sender == address(this)) {
currency.transfer(address(poolManager), amount);
} else {
IERC20Minimal(Currency.unwrap(currency)).transferFrom(sender, address(poolManager), amount);
SafeERC20.safeTransferFrom(IERC20(Currency.unwrap(currency)), sender, address(poolManager), amount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi! please could you use
using SafeERC20 for IERC20
and then just token.safeTransferFrom?

}
poolManager.settle(currency);
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/hooks/examples/LimitOrder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {BaseHook} from "../../BaseHook.sol";
import {Currency, CurrencyLibrary} from "@uniswap/v4-core/src/types/Currency.sol";
import {BalanceDelta} from "@uniswap/v4-core/src/types/BalanceDelta.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

type Epoch is uint232;

Expand Down Expand Up @@ -265,17 +267,15 @@ contract LimitOrder is BaseHook {
if (delta.amount0() < 0) {
if (delta.amount1() != 0) revert InRange();
if (!zeroForOne) revert CrossedRange();
// TODO use safeTransferFrom
IERC20Minimal(Currency.unwrap(key.currency0)).transferFrom(
owner, address(poolManager), uint256(uint128(-delta.amount0()))
SafeERC20.safeTransferFrom(
IERC20(Currency.unwrap(key.currency0)), owner, address(poolManager), uint256(uint128(-delta.amount0()))
);
poolManager.settle(key.currency0);
} else {
if (delta.amount0() != 0) revert InRange();
if (zeroForOne) revert CrossedRange();
// TODO use safeTransferFrom
IERC20Minimal(Currency.unwrap(key.currency1)).transferFrom(
owner, address(poolManager), uint256(uint128(-delta.amount1()))
SafeERC20.safeTransferFrom(
IERC20(Currency.unwrap(key.currency0)), owner, address(poolManager), uint256(uint128(-delta.amount0()))
);
poolManager.settle(key.currency1);
}
Expand Down
Loading