22pragma solidity ^ 0.8.13 ;
33
44import {IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol " ;
5- import {
6- SafeERC20
7- } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol " ;
8- import {
9- IUniswapV2Factory
10- } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol " ;
11- import {
12- IUniswapV2Pair
13- } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol " ;
14- import {
15- IUniswapV2ERC20
16- } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2ERC20.sol " ;
5+ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol " ;
6+ import {IUniswapV2Factory} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol " ;
7+ import {IUniswapV2Pair} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol " ;
8+ import {IUniswapV2ERC20} from "@uniswap/v2-core/contracts/interfaces/IUniswapV2ERC20.sol " ;
179
1810import {IToken} from "./interfaces/IToken.sol " ;
1911import {IGNad} from "./interfaces/IGNad.sol " ;
2012import {IBondingCurveFactory} from "./interfaces/IBondingCurveFactory.sol " ;
2113import {IBondingCurve} from "./interfaces/IBondingCurve.sol " ;
22- import * as CustomErrors from "./errors/CustomErrors.sol " ;
14+ import "./errors/CustomErrors.sol " as CustomErrors ;
2315
2416/**
2517 * @title BondingCurve
@@ -117,10 +109,7 @@ contract BondingCurve is IBondingCurve {
117109 realNativeReserves = IERC20 (WMON).balanceOf (address (this ));
118110 realTokenReserves = IERC20 (_token).balanceOf (address (this ));
119111 lockedToken = _lockedToken;
120- feeConfig = Fee ({
121- denominator: _feeDenominator,
122- numerator: _feeNumerator
123- });
112+ feeConfig = Fee ({denominator: _feeDenominator, numerator: _feeNumerator});
124113 isListing = false ;
125114 }
126115
@@ -135,24 +124,15 @@ contract BondingCurve is IBondingCurve {
135124 address _wMon = WMON; //gas savings
136125 address _token = token; //gas savings
137126
138- (
139- uint256 _realNativeReserves ,
140- uint256 _realTokenReserves
141- ) = getReserves ();
127+ (uint256 _realNativeReserves , uint256 _realTokenReserves ) = getReserves ();
142128
143129 // Ensure remaining tokens stay above target
144- require (
145- _realTokenReserves - amountOut >= lockedToken,
146- CustomErrors.INVALID_LOCKED_AMOUNT
147- );
130+ require (_realTokenReserves - amountOut >= lockedToken, CustomErrors.INVALID_LOCKED_AMOUNT);
148131
149132 uint256 balanceWNative;
150133
151134 {
152- require (
153- to != _wMon && to != _token,
154- CustomErrors.INVALID_RECIPIENT
155- );
135+ require (to != _wMon && to != _token, CustomErrors.INVALID_RECIPIENT);
156136 IERC20 (_token).safeTransfer (GNAD, amountOut);
157137
158138 balanceWNative = IERC20 (_wMon).balanceOf (address (this ));
@@ -176,22 +156,13 @@ contract BondingCurve is IBondingCurve {
176156
177157 address _wMon = WMON;
178158 address _token = token;
179- (
180- uint256 _realNativeReserves ,
181- uint256 _realTokenReserves
182- ) = getReserves ();
183- require (
184- amountOut <= _realNativeReserves,
185- CustomErrors.INVALID_AMOUNT_OUT
186- );
159+ (uint256 _realNativeReserves , uint256 _realTokenReserves ) = getReserves ();
160+ require (amountOut <= _realNativeReserves, CustomErrors.INVALID_AMOUNT_OUT);
187161
188162 uint256 balanceToken;
189163
190164 {
191- require (
192- to != _wMon && to != _token,
193- CustomErrors.INVALID_RECIPIENT
194- );
165+ require (to != _wMon && to != _token, CustomErrors.INVALID_RECIPIENT);
195166 IERC20 (_wMon).safeTransfer (GNAD, amountOut);
196167 balanceToken = IERC20 (_token).balanceOf (address (this ));
197168 }
@@ -213,25 +184,16 @@ contract BondingCurve is IBondingCurve {
213184 require (lock == true , CustomErrors.INVALID_IT_IS_UNLOCKED);
214185 require (! isListing, CustomErrors.INVALID_ALREADY_LISTED);
215186 IBondingCurveFactory _factory = IBondingCurveFactory (FACTORY);
216- pair = IUniswapV2Factory (_factory.getDexFactory ()).createPair (
217- WMON,
218- token
219- );
187+ pair = IUniswapV2Factory (_factory.getDexFactory ()).createPair (WMON, token);
220188 uint256 listingFee = _factory.getListingFee ();
221189
222190 // A token equivalent to the native token consumed as a listing fee is burned.
223191 // Transfer remaining tokens to the pair
224192 uint256 burnTokenAmount;
225193 {
226- burnTokenAmount =
227- realTokenReserves -
228- ((realNativeReserves - listingFee) * virtualToken) /
229- virtualNative;
194+ burnTokenAmount = realTokenReserves - ((realNativeReserves - listingFee) * virtualToken) / virtualNative;
230195 IToken (token).burn (burnTokenAmount);
231- IERC20 (WMON).safeTransfer (
232- IGNad (_factory.getGNad ()).getFeeVault (),
233- listingFee
234- );
196+ IERC20 (WMON).safeTransfer (IGNad (_factory.getGNad ()).getFeeVault (), listingFee);
235197 }
236198
237199 uint256 listingNativeAmount = IERC20 (WMON).balanceOf (address (this ));
@@ -246,14 +208,7 @@ contract BondingCurve is IBondingCurve {
246208
247209 IUniswapV2ERC20 (pair).transfer (address (0 ), liquidity);
248210 isListing = true ;
249- emit Listing (
250- address (this ),
251- token,
252- pair,
253- listingNativeAmount,
254- listingTokenAmount,
255- liquidity
256- );
211+ emit Listing (address (this ), token, pair, listingNativeAmount, listingTokenAmount, liquidity);
257212 return pair;
258213 }
259214
@@ -276,13 +231,7 @@ contract BondingCurve is IBondingCurve {
276231 virtualToken += amountIn;
277232 }
278233
279- emit Sync (
280- token,
281- realNativeReserves,
282- realTokenReserves,
283- virtualNative,
284- virtualToken
285- );
234+ emit Sync (token, realNativeReserves, realTokenReserves, virtualNative, virtualToken);
286235 }
287236
288237 function _checkTarget () private {
@@ -299,12 +248,7 @@ contract BondingCurve is IBondingCurve {
299248 * @return nativeReserves The current real Native reserves
300249 * @return tokenReserves The current real token reserves
301250 */
302- function getReserves ()
303- public
304- view
305- override
306- returns (uint256 nativeReserves , uint256 tokenReserves )
307- {
251+ function getReserves () public view override returns (uint256 nativeReserves , uint256 tokenReserves ) {
308252 return (realNativeReserves, realTokenReserves);
309253 }
310254
@@ -327,11 +271,7 @@ contract BondingCurve is IBondingCurve {
327271 * @return denominator The fee denominator
328272 * @return numerator The fee numerator
329273 */
330- function getFeeConfig ()
331- external
332- view
333- returns (uint8 denominator , uint16 numerator )
334- {
274+ function getFeeConfig () external view returns (uint8 denominator , uint16 numerator ) {
335275 return (feeConfig.denominator, feeConfig.numerator);
336276 }
337277
0 commit comments