Skip to content

Commit 223b8c3

Browse files
committed
add TransferFromSender
1 parent fed3eae commit 223b8c3

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

script/10_Swap.s.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,30 @@ contract Swap is ScriptUtils {
1616
string memory json = getScriptFile(inputScriptFileName);
1717
address uniswapRouterV2 = vm.parseJsonAddress(json, ".uniswapRouterV2");
1818
address uniswapRouterV3 = vm.parseJsonAddress(json, ".uniswapRouterV3");
19+
address evc = vm.parseJsonAddress(json, ".evc");
20+
address permit2 = vm.parseJsonAddress(json, ".permit2");
1921

20-
(swapper, swapVerifier) = execute(uniswapRouterV2, uniswapRouterV3);
22+
(swapper, swapVerifier) = execute(evc, permit2, uniswapRouterV2, uniswapRouterV3);
2123

2224
string memory object;
2325
object = vm.serializeAddress("swap", "swapper", swapper);
2426
object = vm.serializeAddress("swap", "swapVerifier", swapVerifier);
2527
vm.writeJson(object, string.concat(vm.projectRoot(), "/script/", outputScriptFileName));
2628
}
2729

28-
function deploy(address uniswapRouterV2, address uniswapRouterV3)
30+
function deploy(address evc, address permit2, address uniswapRouterV2, address uniswapRouterV3)
2931
public
3032
broadcast
3133
returns (address swapper, address swapVerifier)
3234
{
33-
(swapper, swapVerifier) = execute(uniswapRouterV2, uniswapRouterV3);
35+
(swapper, swapVerifier) = execute(evc, permit2, uniswapRouterV2, uniswapRouterV3);
3436
}
3537

36-
function execute(address uniswapRouterV2, address uniswapRouterV3)
38+
function execute(address evc, address permit2, address uniswapRouterV2, address uniswapRouterV3)
3739
public
3840
returns (address swapper, address swapVerifier)
3941
{
4042
swapper = address(new Swapper(uniswapRouterV2, uniswapRouterV3));
41-
swapVerifier = address(new SwapVerifier());
43+
swapVerifier = address(new SwapVerifier(evc, permit2));
4244
}
4345
}

script/50_CoreAndPeriphery.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ contract CoreAndPeriphery is BatchBuilder, SafeMultisendBuilder {
804804
console.log("+ Deploying Swapper...");
805805
Swap deployer = new Swap();
806806
(peripheryAddresses.swapper, peripheryAddresses.swapVerifier) =
807-
deployer.deploy(input.uniswapV2Router, input.uniswapV3Router);
807+
deployer.deploy(coreAddresses.evc, input.permit2, input.uniswapV2Router, input.uniswapV3Router);
808808
} else {
809809
console.log("- At least one of the Swapper contracts already deployed. Skipping...");
810810
}

src/Swaps/SwapVerifier.sol

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,23 @@
33
pragma solidity ^0.8.0;
44

55
import {IEVault, IERC20} from "evk/EVault/IEVault.sol";
6+
import {TransferFromSender} from "./TransferFromSender.sol";
67

78
/// @title SwapVerifier
89
/// @custom:security-contact security@euler.xyz
910
/// @author Euler Labs (https://www.eulerlabs.com/)
1011
/// @notice Simple contract used to verify post swap conditions
1112
/// @dev This contract is the only trusted code in the EVK swap periphery
12-
contract SwapVerifier {
13+
contract SwapVerifier is TransferFromSender {
1314
error SwapVerifier_skimMin();
1415
error SwapVerifier_debtMax();
1516
error SwapVerifier_pastDeadline();
1617

18+
/// @notice Contract constructor
19+
/// @param evc Address of the EthereumVaultConnector contract
20+
/// @param permit2 Address of the Permit2 contract
21+
constructor(address evc, address permit2) TransferFromSender(evc, permit2) {}
22+
1723
/// @notice Verify results of a regular swap, when bought tokens are sent to the vault and skim for the buyer
1824
/// @param vault The EVault to query
1925
/// @param receiver Account to skim to

src/Swaps/TransferFromSender.sol

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
3+
pragma solidity ^0.8.0;
4+
5+
import {IERC20} from "evk/EVault/IEVault.sol";
6+
import {SafeERC20Lib} from "evk/EVault/shared/lib/SafeERC20Lib.sol";
7+
import {EVCUtil} from "ethereum-vault-connector/utils/EVCUtil.sol";
8+
9+
/// @title TransferFromSender
10+
/// @custom:security-contact security@euler.xyz
11+
/// @author Euler Labs (https://www.eulerlabs.com/)
12+
/// @notice Simple contract used to pull tokens from the sender.
13+
/// @dev This contract is trusted and can safely receive allowance on token transfers from users.
14+
contract TransferFromSender is EVCUtil {
15+
using SafeERC20Lib for IERC20;
16+
17+
error TransferFromSender_InvalidAddress();
18+
19+
/// @notice Address of Permit2 contract
20+
address public immutable permit2;
21+
22+
/// @param _permit2 Address of the Permit2 contract
23+
constructor(address _evc, address _permit2) EVCUtil(_evc) {
24+
if (_permit2 == address(0)) revert TransferFromSender_InvalidAddress();
25+
permit2 = _permit2;
26+
}
27+
28+
/// @notice Pull tokens from sender to the designated receiver
29+
/// @param token ERC20 token address
30+
/// @param amount Amount of the token to transfer
31+
/// @param to Receiver of the token
32+
function transferFromSender(address token, uint256 amount, address to) public {
33+
IERC20(token).safeTransferFrom(_msgSender(), to, amount, permit2);
34+
}
35+
}

test/Swaps/Swaps1Inch.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ contract Swaps1Inch is EVaultTestBase {
5353
user2 = makeAddr("user2");
5454

5555
swapper = new Swapper(uniswapRouterV2, uniswapRouterV3);
56-
swapVerifier = new SwapVerifier();
56+
swapVerifier = new SwapVerifier(address(1), address(1));
5757

5858
if (bytes(FORK_RPC_URL).length != 0) {
5959
mainnetFork = vm.createSelectFork(FORK_RPC_URL);

0 commit comments

Comments
 (0)