File tree Expand file tree Collapse file tree 1 file changed +2
-45
lines changed Expand file tree Collapse file tree 1 file changed +2
-45
lines changed Original file line number Diff line number Diff line change 2
2
pragma solidity ^ 0.8.0 ;
3
3
4
4
import {console} from "forge-std/Test.sol " ;
5
+ import {Math} from "@openzeppelin/contracts/utils/math/Math.sol " ;
5
6
import {MaglevBase} from "./MaglevBase.sol " ;
6
7
7
8
contract MaglevEulerSwap is MaglevBase {
@@ -109,7 +110,7 @@ contract MaglevEulerSwap is MaglevBase {
109
110
+ int256 (y0) * (1e18 - 2 * int256 (cy)) / 1e18 ;
110
111
int256 c = (int256 (cy) - 1e18 ) * int256 (y0) ** 2 / 1e18 / 1e18 ;
111
112
uint256 discriminant = uint256 (int256 (uint256 (b ** 2 )) - 4 * int256 (a) * int256 (c));
112
- uint256 numerator = uint256 (- b + int256 (uint256 (sqrt (discriminant))));
113
+ uint256 numerator = uint256 (- b + int256 (uint256 (Math. sqrt (discriminant))));
113
114
uint256 denominator = 2 * a;
114
115
return numerator * 1e18 / denominator;
115
116
}
@@ -172,48 +173,4 @@ contract MaglevEulerSwap is MaglevBase {
172
173
// if distance is > zero, then point is above the curve, and invariant passes
173
174
return (delta >= 0 );
174
175
}
175
-
176
- // EIP-7054
177
- function sqrt (uint256 x ) internal pure returns (uint128 ) {
178
- if (x == 0 ) {
179
- return 0 ;
180
- } else {
181
- uint256 xx = x;
182
- uint256 r = 1 ;
183
- if (xx >= 0x100000000000000000000000000000000 ) {
184
- xx >>= 128 ;
185
- r <<= 64 ;
186
- }
187
- if (xx >= 0x10000000000000000 ) {
188
- xx >>= 64 ;
189
- r <<= 32 ;
190
- }
191
- if (xx >= 0x100000000 ) {
192
- xx >>= 32 ;
193
- r <<= 16 ;
194
- }
195
- if (xx >= 0x10000 ) {
196
- xx >>= 16 ;
197
- r <<= 8 ;
198
- }
199
- if (xx >= 0x100 ) {
200
- xx >>= 8 ;
201
- r <<= 4 ;
202
- }
203
- if (xx >= 0x10 ) {
204
- xx >>= 4 ;
205
- r <<= 2 ;
206
- }
207
- if (xx >= 0x8 ) r <<= 1 ;
208
- r = (r + x / r) >> 1 ;
209
- r = (r + x / r) >> 1 ;
210
- r = (r + x / r) >> 1 ;
211
- r = (r + x / r) >> 1 ;
212
- r = (r + x / r) >> 1 ;
213
- r = (r + x / r) >> 1 ;
214
- r = (r + x / r) >> 1 ;
215
- uint256 r1 = x / r;
216
- return uint128 (r < r1 ? r : r1);
217
- }
218
- }
219
176
}
You can’t perform that action at this time.
0 commit comments