@@ -56,17 +56,57 @@ contract WAMPL is ERC20, ERC20Permit {
56
56
//--------------------------------------------------------------------------
57
57
// WAMPL write methods
58
58
59
+ /// @notice Transfers AMPLs from {msg.sender} and mints wAMPLs.
60
+ ///
61
+ /// @param wamples The amount of wAMPLs to mint.
62
+ /// @return The amount of AMPLs deposited.
63
+ function mint (uint256 wamples ) external returns (uint256 ) {
64
+ uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
65
+ _deposit (_msgSender (), _msgSender (), amples, wamples);
66
+ return amples;
67
+ }
68
+
69
+ /// @notice Transfers AMPLs from {msg.sender} and mints wAMPLs,
70
+ /// to the specified beneficiary.
71
+ ///
72
+ /// @param to The beneficiary wallet.
73
+ /// @param wamples The amount of wAMPLs to mint.
74
+ /// @return The amount of AMPLs deposited.
75
+ function mintFor (address to , uint256 wamples ) external returns (uint256 ) {
76
+ uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
77
+ _deposit (_msgSender (), to, amples, wamples);
78
+ return amples;
79
+ }
80
+
81
+ /// @notice Burns wAMPLs from {msg.sender} and transfers AMPLs back.
82
+ ///
83
+ /// @param wamples The amount of wAMPLs to burn.
84
+ /// @return The amount of AMPLs withdrawn.
85
+ function burn (uint256 wamples ) external returns (uint256 ) {
86
+ uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
87
+ _withdraw (_msgSender (), _msgSender (), amples, wamples);
88
+ return amples;
89
+ }
90
+
91
+ /// @notice Burns wAMPLs from {msg.sender} and transfers AMPLs back,
92
+ /// to the specified beneficiary.
93
+ ///
94
+ /// @param to The beneficiary wallet.
95
+ /// @param wamples The amount of wAMPLs to burn.
96
+ /// @return The amount of AMPLs withdrawn.
97
+ function burnTo (address to , uint256 wamples ) external returns (uint256 ) {
98
+ uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
99
+ _withdraw (_msgSender (), to, amples, wamples);
100
+ return amples;
101
+ }
102
+
59
103
/// @notice Transfers AMPLs from {msg.sender} and mints wAMPLs.
60
104
///
61
105
/// @param amples The amount of AMPLs to deposit.
62
106
/// @return The amount of wAMPLs minted.
63
107
function deposit (uint256 amples ) external returns (uint256 ) {
64
108
uint256 wamples = _ampleToWample (amples, _queryAMPLSupply ());
65
-
66
- IERC20 (_ampl).safeTransferFrom (_msgSender (), address (this ), amples);
67
-
68
- _mint (_msgSender (), wamples);
69
-
109
+ _deposit (_msgSender (), _msgSender (), amples, wamples);
70
110
return wamples;
71
111
}
72
112
@@ -78,11 +118,7 @@ contract WAMPL is ERC20, ERC20Permit {
78
118
/// @return The amount of wAMPLs minted.
79
119
function depositFor (address to , uint256 amples ) external returns (uint256 ) {
80
120
uint256 wamples = _ampleToWample (amples, _queryAMPLSupply ());
81
-
82
- IERC20 (_ampl).safeTransferFrom (_msgSender (), address (this ), amples);
83
-
84
- _mint (to, wamples);
85
-
121
+ _deposit (_msgSender (), to, amples, wamples);
86
122
return wamples;
87
123
}
88
124
@@ -92,11 +128,7 @@ contract WAMPL is ERC20, ERC20Permit {
92
128
/// @return The amount of burnt wAMPLs.
93
129
function withdraw (uint256 amples ) external returns (uint256 ) {
94
130
uint256 wamples = _ampleToWample (amples, _queryAMPLSupply ());
95
-
96
- _burn (_msgSender (), wamples);
97
-
98
- IERC20 (_ampl).safeTransfer (_msgSender (), amples);
99
-
131
+ _withdraw (_msgSender (), _msgSender (), amples, wamples);
100
132
return wamples;
101
133
}
102
134
@@ -108,11 +140,7 @@ contract WAMPL is ERC20, ERC20Permit {
108
140
/// @return The amount of burnt wAMPLs.
109
141
function withdrawTo (address to , uint256 amples ) external returns (uint256 ) {
110
142
uint256 wamples = _ampleToWample (amples, _queryAMPLSupply ());
111
-
112
- _burn (_msgSender (), wamples);
113
-
114
- IERC20 (_ampl).safeTransfer (to, amples);
115
-
143
+ _withdraw (_msgSender (), to, amples, wamples);
116
144
return wamples;
117
145
}
118
146
@@ -121,13 +149,8 @@ contract WAMPL is ERC20, ERC20Permit {
121
149
/// @return The amount of burnt wAMPLs.
122
150
function withdrawAll () external returns (uint256 ) {
123
151
uint256 wamples = balanceOf (_msgSender ());
124
-
125
152
uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
126
-
127
- _burn (_msgSender (), wamples);
128
-
129
- IERC20 (_ampl).safeTransfer (_msgSender (), amples);
130
-
153
+ _withdraw (_msgSender (), _msgSender (), amples, wamples);
131
154
return wamples;
132
155
}
133
156
@@ -138,76 +161,11 @@ contract WAMPL is ERC20, ERC20Permit {
138
161
/// @return The amount of burnt wAMPLs.
139
162
function withdrawAllTo (address to ) external returns (uint256 ) {
140
163
uint256 wamples = balanceOf (_msgSender ());
141
-
142
164
uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
143
-
144
- _burn (_msgSender (), wamples);
145
-
146
- IERC20 (_ampl).safeTransfer (to, amples);
147
-
165
+ _withdraw (_msgSender (), to, amples, wamples);
148
166
return wamples;
149
167
}
150
168
151
- /// @notice Transfers AMPLs from {msg.sender} and mints wAMPLs.
152
- ///
153
- /// @param wamples The amount of wAMPLs to mint.
154
- /// @return The amount of AMPLs deposited.
155
- function mint (uint256 wamples ) external returns (uint256 ) {
156
- uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
157
-
158
- IERC20 (_ampl).safeTransferFrom (_msgSender (), address (this ), amples);
159
-
160
- _mint (_msgSender (), wamples);
161
-
162
- return amples;
163
- }
164
-
165
- /// @notice Transfers AMPLs from {msg.sender} and mints wAMPLs,
166
- /// to the specified beneficiary.
167
- ///
168
- /// @param to The beneficiary wallet.
169
- /// @param wamples The amount of wAMPLs to mint.
170
- /// @return The amount of AMPLs deposited.
171
- function mintTo (address to , uint256 wamples ) external returns (uint256 ) {
172
- uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
173
-
174
- IERC20 (_ampl).safeTransferFrom (_msgSender (), address (this ), amples);
175
-
176
- _mint (to, wamples);
177
-
178
- return amples;
179
- }
180
-
181
- /// @notice Burns wAMPLs from {msg.sender} and transfers AMPLs back.
182
- ///
183
- /// @param wamples The amount of wAMPLs to burn.
184
- /// @return The amount of AMPLs withdrawn.
185
- function burn (uint256 wamples ) external returns (uint256 ) {
186
- uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
187
-
188
- _burn (_msgSender (), wamples);
189
-
190
- IERC20 (_ampl).safeTransfer (_msgSender (), amples);
191
-
192
- return amples;
193
- }
194
-
195
- /// @notice Burns wAMPLs from {msg.sender} and transfers AMPLs back,
196
- /// to the specified beneficiary.
197
- ///
198
- /// @param to The beneficiary wallet.
199
- /// @param wamples The amount of wAMPLs to burn.
200
- /// @return The amount of AMPLs withdrawn.
201
- function burnTo (address to , uint256 wamples ) external returns (uint256 ) {
202
- uint256 amples = _wampleToAmple (wamples, _queryAMPLSupply ());
203
-
204
- _burn (_msgSender (), wamples);
205
-
206
- IERC20 (_ampl).safeTransfer (to, amples);
207
-
208
- return amples;
209
- }
210
-
211
169
//--------------------------------------------------------------------------
212
170
// WAMPL view methods
213
171
@@ -228,21 +186,54 @@ contract WAMPL is ERC20, ERC20Permit {
228
186
}
229
187
230
188
/// @param amples The amount of AMPL tokens.
231
- /// @return The amount of wAMPL tokens mintable .
189
+ /// @return The amount of wAMPL tokens exchangeable .
232
190
function underlyingToWrapper (uint256 amples ) external view returns (uint256 ) {
233
191
return _ampleToWample (amples, _queryAMPLSupply ());
234
192
}
235
193
236
194
/// @param wamples The amount of wAMPL tokens.
237
- /// @return The amount of AMPL tokens redeemable .
195
+ /// @return The amount of AMPL tokens exchangeable .
238
196
function wrapperToUnderlying (uint256 wamples ) external view returns (uint256 ) {
239
197
return _wampleToAmple (wamples, _queryAMPLSupply ());
240
198
}
241
199
242
200
//--------------------------------------------------------------------------
243
201
// Private methods
244
202
203
+ /// @dev Internal helper function to handle deposit state change.
204
+ /// @param from The initiator wallet.
205
+ /// @param to The beneficiary wallet.
206
+ /// @param amples The amount of AMPLs to deposit.
207
+ /// @param wamples The amount of wAMPLs to mint.
208
+ function _deposit (
209
+ address from ,
210
+ address to ,
211
+ uint256 amples ,
212
+ uint256 wamples
213
+ ) private {
214
+ IERC20 (_ampl).safeTransferFrom (from, address (this ), amples);
215
+
216
+ _mint (to, wamples);
217
+ }
218
+
219
+ /// @dev Internal helper function to handle withdraw state change.
220
+ /// @param from The initiator wallet.
221
+ /// @param to The beneficiary wallet.
222
+ /// @param amples The amount of AMPLs to withdraw.
223
+ /// @param wamples The amount of wAMPLs to burn.
224
+ function _withdraw (
225
+ address from ,
226
+ address to ,
227
+ uint256 amples ,
228
+ uint256 wamples
229
+ ) private {
230
+ _burn (from, wamples);
231
+
232
+ IERC20 (_ampl).safeTransfer (to, amples);
233
+ }
234
+
245
235
/// @dev Queries the current total supply of AMPL.
236
+ /// @return The current AMPL supply.
246
237
function _queryAMPLSupply () private view returns (uint256 ) {
247
238
return IERC20 (_ampl).totalSupply ();
248
239
}
0 commit comments