Skip to content

Commit 232842e

Browse files
Add minting fee
1 parent 40ec10c commit 232842e

File tree

4 files changed

+248
-35
lines changed

4 files changed

+248
-35
lines changed

src/Fraxiversarry.sol

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ contract Fraxiversarry is
3737
using ONFT721MsgCodec for bytes32;
3838

3939
address public constant WFRAX_ADDRESS = 0xFc00000000000000000000000000000000000002;
40+
uint256 public constant MAX_BASIS_POINTS = 1e4;
4041

4142
mapping(address erc20 => uint256 price) public mintPrices;
4243
mapping(address erc20 => string uri) public baseAssetTokenUris;
44+
mapping(address erc20 => uint256 fee) public collectedFees;
4345
mapping(uint256 index => address erc20) public supportedErc20s;
4446
mapping(uint256 tokenId => mapping(uint256 index => address underlyingAsset)) public underlyingAssets;
4547
mapping(uint256 tokenId => uint256 numberOfAssets) public numberOfTokenUnderlyingAssets;
@@ -56,6 +58,7 @@ contract Fraxiversarry is
5658
uint256 public mintingLimit;
5759
uint256 public giftMintingLimit;
5860
uint256 public giftMintingPrice;
61+
uint256 public mintingFeeBasisPoints;
5962

6063
bool private _isBridgeOperation;
6164

@@ -79,6 +82,7 @@ contract Fraxiversarry is
7982
giftMintingPrice = 50 * 1e18; // 50 WFRAX
8083
nextGiftTokenId = mintingLimit;
8184
nextPremiumTokenId = mintingLimit + giftMintingLimit;
85+
mintingFeeBasisPoints = 25; // 0.25%
8286

8387
//TODO: Set correct URIs
8488
giftTokenUri = "https://gift.tba.frax/";
@@ -298,6 +302,41 @@ contract Fraxiversarry is
298302
emit GiftMintPriceUpdated(previousPrice, newPrice);
299303
}
300304

305+
function updateMintingFeeBasisPoints(uint256 newFeeBasisPoints) public onlyOwner {
306+
if (newFeeBasisPoints > MAX_BASIS_POINTS) revert OutOfBounds();
307+
308+
uint256 previousFeeBasisPoints = mintingFeeBasisPoints;
309+
mintingFeeBasisPoints = newFeeBasisPoints;
310+
311+
emit MintingFeeUpdated(previousFeeBasisPoints, newFeeBasisPoints);
312+
}
313+
314+
function retrieveCollectedFees(address erc20Contract, address to) public onlyOwner {
315+
uint256 feeAmount = collectedFees[erc20Contract];
316+
if (feeAmount == 0) return;
317+
318+
collectedFees[erc20Contract] = 0;
319+
if (!IERC20(erc20Contract).transfer(to, feeAmount)) revert TransferFailed();
320+
321+
emit FeesRetrieved(erc20Contract, to, feeAmount);
322+
}
323+
324+
function getMintingPriceWithFee(address erc20Contract)
325+
public
326+
view
327+
returns (uint256 mintPrice, uint256 fee, uint256 totalPrice)
328+
{
329+
mintPrice = mintPrices[erc20Contract];
330+
fee = (mintPrice * mintingFeeBasisPoints) / MAX_BASIS_POINTS;
331+
totalPrice = mintPrice + fee;
332+
}
333+
334+
function getGiftMintingPriceWithFee() public view returns (uint256 mintPrice, uint256 fee, uint256 totalPrice) {
335+
mintPrice = giftMintingPrice;
336+
fee = (mintPrice * mintingFeeBasisPoints) / MAX_BASIS_POINTS;
337+
totalPrice = mintPrice + fee;
338+
}
339+
301340
function getUnderlyingTokenIds(uint256 premiumTokenId)
302341
external
303342
view
@@ -513,15 +552,19 @@ contract Fraxiversarry is
513552

514553
function _transferERC20ToToken(address erc20Contract, uint256 tokenId, address from, uint256 amount) internal {
515554
IERC20 erc20Token = IERC20(erc20Contract);
555+
uint256 fee = (amount * mintingFeeBasisPoints) / MAX_BASIS_POINTS;
556+
uint256 amountWithFee = amount + fee;
516557

517-
if (erc20Token.allowance(from, address(this)) < amount) revert InsufficientAllowance();
518-
if (erc20Token.balanceOf(from) < amount) revert InsufficientBalance();
558+
if (erc20Token.allowance(from, address(this)) < amountWithFee) revert InsufficientAllowance();
559+
if (erc20Token.balanceOf(from) < amountWithFee) revert InsufficientBalance();
519560

520-
if (!erc20Token.transferFrom(from, address(this), amount)) revert TransferFailed();
561+
if (!erc20Token.transferFrom(from, address(this), amountWithFee)) revert TransferFailed();
521562

522563
erc20Balances[tokenId][erc20Contract] += amount;
564+
collectedFees[erc20Contract] += fee;
523565

524566
emit ReceivedERC20(erc20Contract, tokenId, from, amount);
567+
emit FeeCollected(erc20Contract, from, fee);
525568
}
526569

527570
// ********** Internal functions to facilitate the ONFT operations **********

src/interfaces/IFraxiversarryEvents.sol

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
pragma solidity ^0.8.30;
33

44
contract IFraxiversarryEvents {
5+
event FeeCollected(address indexed erc20Contract, address indexed from, uint256 feeAmount);
6+
7+
event FeesRetrieved(address indexed erc20Contract, address indexed to, uint256 feeAmount);
8+
59
event GiftMinted(address indexed minter, address indexed recipient, uint256 tokenId, uint256 mintPrice);
610

711
event GiftMintPriceUpdated(uint256 previousMintPrice, uint256 newMintPrice);
812

13+
event MintingFeeUpdated(uint256 previousFeeBasisPoints, uint256 newFeeBasisPoints);
14+
915
event MintPriceUpdated(address indexed erc20Contract, uint256 previousMintPrice, uint256 newMintPrice);
1016

1117
event NewSoulboundToken(address indexed tokenOwner, uint256 tokenId);

0 commit comments

Comments
 (0)