-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathironvault.sol
More file actions
169 lines (137 loc) · 6.21 KB
/
Copy pathironvault.sol
File metadata and controls
169 lines (137 loc) · 6.21 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// SPDX-License-Identifier: MIT-0
pragma solidity =0.8.0;
pragma experimental ABIEncoderV2;
// Contracts needed: IronChef -> DfynRouter -> IronSwap -> IronChef
// "IronVault: Error Message"
interface IERC20 {
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}
interface IDFYNRouter {
function swapExactTokensForTokens(uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline) external returns (uint[] memory amounts);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
}
interface IIronSwap {
function addLiquidity(uint256[] memory amounts, uint256 minMintAmount, uint256 deadline) external returns (uint256);
function removeLiquidity(uint256 lpAmount, uint256[] memory minAmounts, uint256 deadline) external returns (uint256);
}
interface IIronChef {
function harvest(uint256 pid, address to) external;
function deposit(uint256 pid, uint256 amount, address to) external;
function emergencyWithdraw(uint256 pid, address to) external;
}
contract IronVault {
address public owner;
IERC20 public ICE = IERC20(0x4A81f8796e0c6Ad4877A51C86693B0dE8093F2ef);
IERC20 public IS3USD = IERC20(0xb4d09ff3dA7f9e9A2BA029cb0A81A989fd7B8f17);
IERC20 public USDC = IERC20(0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174);
IIronChef public IronChef = IIronChef(0x1fD1259Fa8CdC60c6E8C86cfA592CA1b8403DFaD);
IDFYNRouter public DFYNRouter = IDFYNRouter(0xA102072A4C07F06EC3B4900FDC4C7B80b6c57429);
IIronSwap public IronSwap = IIronSwap(0x837503e8A8753ae17fB8C8151B8e6f586defCb57);
uint256 public slippage = 1; // Solidity does not support decimals
uint256 public pid;
// time for unix timestamps
uint constant TWENTY_MINUTES = 1200; // in seconds
//events
event OwnershipTransferred(address oldOwner, address newOwner);
event UpdatePoolId(uint256 oldPool, uint256 newPool);
// Initially set contract parameters and variables
constructor(
uint256 _pid
/*
address _ironChef,
address _ironSwap,
address _iDfynRouter
pid: 0
ironchef: 0x1fD1259Fa8CdC60c6E8C86cfA592CA1b8403DFaD
ironSwap: 0x837503e8A8753ae17fB8C8151B8e6f586defCb57
dfynRouter: 0xA102072A4C07F06EC3B4900FDC4C7B80b6c57429
*/
) {
owner = msg.sender;
/*
IronChef = IIronChef(_ironChef);
DFYNRouter = IDFYNRouter(_iDfynRouter);
IronSwap = IIronSwap(_ironSwap);
*/
// Customizable pool ID
pid = _pid;
// Unlimited approve token on RToken address
ICE.approve(address(DFYNRouter), 2**256 - 1);
USDC.approve(address(IronSwap), 2**256 - 1);
IS3USD.approve(address(IronChef), 2**256 - 1);
}
modifier onlyOwner {
require(owner == msg.sender, "IronVault: caller is not the owner");
_;
}
function updatePoolId(uint256 _newPid) external onlyOwner {
if (_newPid != pid) {
//update pool id for iron farms
uint256 oldPool = pid;
pid = _newPid;
emit UpdatePoolId(oldPool, pid);
}
}
function depositToIron() public onlyOwner {
// send IS3USD tokens into pool 0 (stable pool)
require(IS3USD.balanceOf(address(this)) != 0, "IronVault: No IS3USD tokens to deposit");
IronChef.deposit(pid, IS3USD.balanceOf(address(this)), address(this));
}
function compound() public onlyOwner {
claimReward();
require(ICE.balanceOf(address(this)) != 0, "IronVault: No ICE tokens to swap for USDC");
address[] memory path = new address[](2);
path[0] = address(ICE);
path[1] = address(USDC);
// claim ICE, swap ICE for USDC DONE
// DONE: Deposit USDC into IronSwap LP function to recieve IS3USD Tokens
// DONE: Stake IS3USD into IronChef, compound complete.
claimReward();
DFYNRouter.swapExactTokensForTokens(
ICE.balanceOf(address(this)),
0,
path,
address(this),
(block.timestamp + TWENTY_MINUTES)
);
uint256[] memory amounts = new uint256[](3);
amounts[0] = USDC.balanceOf(address(this));
amounts[1] = 0; // no USDT
amounts[2] = 0; // no DAI
IronSwap.addLiquidity(
amounts,
0,
(block.timestamp + TWENTY_MINUTES)
);
depositToIron();
}
function claimReward() public onlyOwner {
IronChef.harvest(pid, address(this));
}
function claimRewardToOwner() public onlyOwner {
// claim rewards and directly send all ICE tokens to owner address
IronChef.harvest(pid, address(this));
ICE.transfer(owner, ICE.balanceOf(address(this)));
}
// This function needs testing
function emergencyWithdrawFromIronONCE() public onlyOwner {
IronChef.harvest(0, address(this));
IronChef.emergencyWithdraw(pid, address(this));
ICE.transfer(address(owner), ICE.balanceOf(address(this)));
IS3USD.transfer(address(owner), IS3USD.balanceOf(address(this)));
}
function WithdrawTokensFromContract(address _tokenContract) external onlyOwner {
// in case functions do not work, manually withdraw standard tokens from the contract.
IERC20 tokenContract = IERC20(_tokenContract);
// transfer the token from address of this contract to the owner
tokenContract.transfer(owner, tokenContract.balanceOf(address(this)));
}
function call(address payable _to, uint256 _value, bytes calldata _data) external payable onlyOwner returns (bytes memory) {
(bool success, bytes memory result) = _to.call{value: _value}(_data);
require(success, "IronVault: external call failed");
return result;
}
}