@@ -111,23 +111,22 @@ contract WOETH is ERC4626, Governable, Initializable {
111
111
* be able to rebase.
112
112
*
113
113
* @param oethAmount Amount of OETH to be converted to OETH credits
114
+ * @param roundUp when true round the amount of credits returned up
114
115
* @return amount of OETH credits the OETH amount corresponds to
115
116
*/
116
- function _oethToCredits (uint256 oethAmount ) internal returns (uint256 ) {
117
+ function _oethToCredits (uint256 oethAmount , bool roundUp ) internal returns (uint256 ) {
117
118
uint256 creditsPerTokenHighres = OETH (asset ())
118
119
.rebasingCreditsPerTokenHighres ();
119
120
120
121
/**
121
122
* Multiplying OETH amount with the creditsPerTokenHighres is exactly the math that
122
- * is internally being done in OETH. (Except that in case of OUSD it is being rounded up)
123
+ * is internally being done in OETH. OETH is always rounding up, WOETH is rounding
124
+ * up / down depending on what favours this contract
123
125
*/
124
126
// solhint-disable-next-line max-line-length
125
127
/** https://github.com/OriginProtocol/origin-dollar/blob/c02572bd1c06eb3c2652c8692e52144be2efa741/contracts/contracts/token/OUSD.sol#L498
126
- *
127
- * This should make sure that the rounding will always be correct / mimic the rounding
128
- * of OETH.
129
128
*/
130
- return oethAmount.mulTruncate (creditsPerTokenHighres);
129
+ return ( oethAmount + (roundUp ? 1e18 - 1 : 0 )) .mulTruncate (creditsPerTokenHighres);
131
130
}
132
131
133
132
/** @dev See {IERC4262-totalAssets} */
@@ -145,7 +144,7 @@ contract WOETH is ERC4626, Governable, Initializable {
145
144
returns (uint256 woethAmount )
146
145
{
147
146
woethAmount = super .deposit (oethAmount, receiver);
148
- oethCreditsHighres += _oethToCredits (oethAmount);
147
+ oethCreditsHighres += _oethToCredits (oethAmount, false );
149
148
}
150
149
151
150
/** @dev See {IERC4262-mint} */
@@ -155,7 +154,7 @@ contract WOETH is ERC4626, Governable, Initializable {
155
154
returns (uint256 oethAmount )
156
155
{
157
156
oethAmount = super .mint (woethAmount, receiver);
158
- oethCreditsHighres += _oethToCredits (oethAmount);
157
+ oethCreditsHighres += _oethToCredits (oethAmount, false );
159
158
}
160
159
161
160
/** @dev See {IERC4262-withdraw} */
@@ -165,7 +164,7 @@ contract WOETH is ERC4626, Governable, Initializable {
165
164
address owner
166
165
) public override returns (uint256 woethAmount ) {
167
166
woethAmount = super .withdraw (oethAmount, receiver, owner);
168
- oethCreditsHighres -= _oethToCredits (oethAmount);
167
+ oethCreditsHighres -= _oethToCredits (oethAmount, true );
169
168
}
170
169
171
170
/** @dev See {IERC4262-redeem} */
@@ -175,6 +174,6 @@ contract WOETH is ERC4626, Governable, Initializable {
175
174
address owner
176
175
) public override returns (uint256 oethAmount ) {
177
176
oethAmount = super .redeem (woethAmount, receiver, owner);
178
- oethCreditsHighres -= _oethToCredits (oethAmount);
177
+ oethCreditsHighres -= _oethToCredits (oethAmount, true );
179
178
}
180
179
}
0 commit comments