Skip to content

Commit c29fb52

Browse files
authored
Merge pull request #5 from angel10x/dev
Dev
2 parents acd3160 + f0559ff commit c29fb52

20 files changed

+1524
-518
lines changed

src/BondingCurve.sol

Lines changed: 19 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,16 @@
22
pragma solidity ^0.8.13;
33

44
import {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

1810
import {IToken} from "./interfaces/IToken.sol";
1911
import {IGNad} from "./interfaces/IGNad.sol";
2012
import {IBondingCurveFactory} from "./interfaces/IBondingCurveFactory.sol";
2113
import {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

src/BondingCurveFactory.sol

Lines changed: 15 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {IBondingCurveFactory} from "./interfaces/IBondingCurveFactory.sol";
66
import {IToken} from "./interfaces/IToken.sol";
77
import {Token} from "./Token.sol";
88
import {BondingCurve} from "./BondingCurve.sol";
9-
import * as CustomErrors from "./errors/CustomErrors.sol";
9+
import "./errors/CustomErrors.sol" as CustomErrors;
1010

1111
/**
1212
* @title BondingCurveFactory
@@ -92,20 +92,10 @@ contract BondingCurveFactory is IBondingCurveFactory {
9292
* @return virtualNative Initial virtual NAD reserve
9393
* @return virtualToken Initial virtual token reserve
9494
*/
95-
function create(
96-
address creator,
97-
string memory name,
98-
string memory symbol,
99-
string memory tokenURI
100-
)
95+
function create(address creator, string memory name, string memory symbol, string memory tokenURI)
10196
external
10297
onlyGnad
103-
returns (
104-
address bc,
105-
address token,
106-
uint256 virtualNative,
107-
uint256 virtualToken
108-
)
98+
returns (address bc, address token, uint256 virtualNative, uint256 virtualToken)
10999
{
110100
Config memory _config = getConfig();
111101

@@ -114,29 +104,21 @@ contract BondingCurveFactory is IBondingCurveFactory {
114104

115105
IToken(token).mint(bc);
116106

117-
IBondingCurve(bc).initialize(
118-
token,
119-
_config.virtualNative,
120-
_config.virtualToken,
121-
_config.k,
122-
_config.targetToken,
123-
_config.feeDenominator,
124-
_config.feeNumerator
125-
);
107+
IBondingCurve(bc)
108+
.initialize(
109+
token,
110+
_config.virtualNative,
111+
_config.virtualToken,
112+
_config.k,
113+
_config.targetToken,
114+
_config.feeDenominator,
115+
_config.feeNumerator
116+
);
126117

127118
bcs[token] = bc;
128119
virtualNative = _config.virtualNative;
129120
virtualToken = _config.virtualToken;
130-
emit Create(
131-
creator,
132-
bc,
133-
token,
134-
tokenURI,
135-
name,
136-
symbol,
137-
virtualNative,
138-
virtualToken
139-
);
121+
emit Create(creator, bc, token, tokenURI, name, symbol, virtualNative, virtualToken);
140122
}
141123

142124
/**
@@ -226,11 +208,7 @@ contract BondingCurveFactory is IBondingCurveFactory {
226208
* @return denominator Fee denominator
227209
* @return numerator Fee numerator
228210
*/
229-
function getFeeConfig()
230-
public
231-
view
232-
returns (uint8 denominator, uint16 numerator)
233-
{
211+
function getFeeConfig() public view returns (uint8 denominator, uint16 numerator) {
234212
return (config.feeDenominator, config.feeNumerator);
235213
}
236214

src/FeeVault.sol

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ contract FeeVault is IFeeVault {
2222
uint256 public ownerCount;
2323
uint256 public proposalCount;
2424

25-
// Withdrawal proposal structure
26-
struct WithdrawalProposal {
27-
address receiver;
28-
uint256 amount;
29-
uint256 signatureCount;
30-
mapping(address => bool) hasSignedWithdrawal;
31-
bool executed;
32-
}
33-
3425
/**
3526
* @notice Fallback function to receive WMON
3627
* @dev Only accepts WMON from the WMON contract
@@ -45,11 +36,7 @@ contract FeeVault is IFeeVault {
4536
* @param _owners Initial list of owner addresses
4637
* @param _requiredSignatures Number of signatures required for withdrawal
4738
*/
48-
constructor(
49-
address _wMon,
50-
address[] memory _owners,
51-
uint256 _requiredSignatures
52-
) {
39+
constructor(address _wMon, address[] memory _owners, uint256 _requiredSignatures) {
5340
require(_wMon != address(0), "ERR_FEE_VAULT_INVALID_WMON_ADDRESS");
5441
require(_owners.length > 0, "ERR_FEE_VAULT_NO_OWNERS");
5542
require(
@@ -90,10 +77,7 @@ contract FeeVault is IFeeVault {
9077
* @param receiver Address to receive the withdrawn assets
9178
* @param amount Amount of WMON to withdraw
9279
*/
93-
function proposeWithdrawal(
94-
address receiver,
95-
uint256 amount
96-
) external onlyOwner {
80+
function proposeWithdrawal(address receiver, uint256 amount) external onlyOwner {
9781
require(receiver != address(0), "ERR_FEE_VAULT_INVALID_RECEIVER");
9882
require(amount > 0, "ERR_FEE_VAULT_INVALID_AMOUNT");
9983
require(amount <= totalAssets(), "ERR_FEE_VAULT_INSUFFICIENT_BALANCE");
@@ -115,15 +99,9 @@ contract FeeVault is IFeeVault {
11599
*/
116100
function signWithdrawal(uint256 proposalId) external onlyOwner {
117101
WithdrawalProposal storage proposal = withdrawalProposals[proposalId];
118-
require(
119-
proposal.receiver != address(0),
120-
"ERR_FEE_VAULT_INVALID_PROPOSAL"
121-
);
102+
require(proposal.receiver != address(0), "ERR_FEE_VAULT_INVALID_PROPOSAL");
122103
require(!proposal.executed, "ERR_FEE_VAULT_ALREADY_EXECUTED");
123-
require(
124-
!proposal.hasSignedWithdrawal[msg.sender],
125-
"ERR_FEE_VAULT_ALREADY_SIGNED"
126-
);
104+
require(!proposal.hasSignedWithdrawal[msg.sender], "ERR_FEE_VAULT_ALREADY_SIGNED");
127105

128106
proposal.hasSignedWithdrawal[msg.sender] = true;
129107
proposal.signatureCount++;
@@ -142,11 +120,7 @@ contract FeeVault is IFeeVault {
142120
* @param proposalId ID of the withdrawal proposal
143121
* @param amount Amount of WMON to withdraw
144122
*/
145-
function _executeWithdrawal(
146-
address receiver,
147-
uint256 proposalId,
148-
uint256 amount
149-
) private {
123+
function _executeWithdrawal(address receiver, uint256 proposalId, uint256 amount) private {
150124
IWMon(WMON).withdraw(amount);
151125

152126
emit WithdrawalExecuted(proposalId, receiver, amount);

0 commit comments

Comments
 (0)