-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathTransferProxyFactory.sol
51 lines (40 loc) · 1.84 KB
/
TransferProxyFactory.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity 0.8.26;
import {SafeTransferLib} from "src/libraries/SafeTransferLib.sol";
import {IPoolManager} from "src/interfaces/IPoolManager.sol";
import {ITransferProxy, ITransferProxyFactory} from "src/interfaces/factories/ITransferProxy.sol";
contract TransferProxy is ITransferProxy {
IPoolManager public immutable poolManager;
bytes32 public immutable destination;
constructor(address poolManager_, bytes32 destination_) {
poolManager = IPoolManager(poolManager_);
destination = destination_;
}
/// @inheritdoc ITransferProxy
function transfer(address asset, uint128 amount) external {
poolManager.transferAssets(asset, destination, amount);
}
}
interface TransferProxyFactoryLike {
function newTransferProxy(address poolManager, bytes32 destination) external returns (address);
}
/// @title Restricted Transfer Proxy Factory
/// @dev Utility for deploying contracts that have a fixed destination for transfers
/// Users can send tokens to the TransferProxy, from a service that only supports
/// ERC20 transfers and not full contract calls.
contract TransferProxyFactory is ITransferProxyFactory {
address public immutable poolManager;
/// @inheritdoc ITransferProxyFactory
mapping(bytes32 id => address proxy) public proxies;
constructor(address poolManager_) {
poolManager = poolManager_;
}
/// @inheritdoc ITransferProxyFactory
function newTransferProxy(bytes32 destination) public returns (address) {
require(proxies[destination] == address(0), "TransferProxyFactory/proxy-already-deployed");
address proxy = address(new TransferProxy(poolManager, destination));
proxies[destination] = proxy;
emit DeployTransferProxy(destination, proxy);
return proxy;
}
}