-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFarmerFactory.sol
73 lines (64 loc) · 2.53 KB
/
FarmerFactory.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "./lib/ProxyFactory.sol";
/// @dev Factory contract used to deploy farmer proxy contracts that store interest bearing assets
/// and rewards / goverance tokens. You can build your own custom factory contract that inherits
/// from this FarmerFactory contract.
contract FarmerFactory is ProxyFactory {
/// Maps user address to the address of deployed farmer proxy.
mapping (address => address) public farmerProxy;
/// Logic contract's address
address public logicContract;
/// @dev Constructor that accepts and stores the address of the logicContract.
/// @param _logicContract The address of the logic contract that the farmer proxies use.
constructor(
address _logicContract
) public {
logicContract = _logicContract;
}
/// @dev Creates and deploys a new farmer proxy contract on behalf of the user.
/// @param proxyUser The address of the user the farmer proxy is deployed for.
/// @param assetToken The address of the interest bearing asset token.
/// @param underlyingToken The address of the underlying token.
/// @param rewardsToken The address of the rewards or governance token.
/// @return proxy Return the newly created farmer proxy's address
function deployProxy(
address proxyUser,
address assetToken,
address underlyingToken,
address rewardsToken)
public
virtual
returns (address proxy)
{
bytes memory data = _encodeData(
assetToken,
underlyingToken,
rewardsToken);
proxy = deployMinimal(logicContract, data);
farmerProxy[proxyUser] = proxy;
return proxy;
}
/// @dev Encodes the data necessary to make low-level call and deploy the farmer proxy.
/// @param assetToken The address of the interest bearing asset token.
/// @param underlyingToken The address of the underlying token.
/// @param rewardsToken The address of the rewards or governance token.
/// @return Return the encoded data necessary to make low-level call.
function _encodeData(
address assetToken,
address underlyingToken,
address rewardsToken)
internal
view
returns (bytes memory)
{
bytes4 selector = 0xf8c8765e;
return abi.encodeWithSelector(
selector,
address(this),
assetToken,
underlyingToken,
rewardsToken
);
}
}