Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ReentrancyGuard #32

Merged
merged 1 commit into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions contracts/core/SharesFactoryV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

pragma solidity 0.8.25;

import "@openzeppelin/contracts/access/Ownable2Step.sol";

Check warning on line 5 in contracts/core/SharesFactoryV1.sol

View workflow job for this annotation

GitHub Actions / lint (18)

global import of path @openzeppelin/contracts/access/Ownable2Step.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Check warning on line 5 in contracts/core/SharesFactoryV1.sol

View workflow job for this annotation

GitHub Actions / lint (18)

global import of path @openzeppelin/contracts/access/Ownable2Step.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

Check warning on line 6 in contracts/core/SharesFactoryV1.sol

View workflow job for this annotation

GitHub Actions / lint (18)

global import of path @openzeppelin/contracts/security/ReentrancyGuard.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)

Check warning on line 6 in contracts/core/SharesFactoryV1.sol

View workflow job for this annotation

GitHub Actions / lint (18)

global import of path @openzeppelin/contracts/security/ReentrancyGuard.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IShare } from "../interface/IShare.sol";
import { IYieldAggregator } from "contracts/interface/IYieldAggregator.sol";
import { BondingCurveLib } from "../lib/BondingCurveLib.sol";

contract SharesFactoryV1 is Ownable2Step {
contract SharesFactoryV1 is Ownable2Step, ReentrancyGuard {
using SafeERC20 for IERC20;

struct Curve {
Expand Down Expand Up @@ -212,7 +213,7 @@
* @param quantity The quantity of shares.
* @param referral The address of the referral fee recipient.
*/
function buyShare(uint256 shareId, uint32 quantity, address referral) public payable {
function buyShare(uint256 shareId, uint32 quantity, address referral) public payable nonReentrant {
require(address(yieldAggregator) != address(0), "Invalid yieldAggregator");
require(shareId < shareIndex, "Invalid shareId");

Expand All @@ -224,6 +225,10 @@
) = getBuyPriceAfterFee(shareId, quantity, referral);
require(msg.value >= buyPriceAfterFee, "Insufficient payment");

// Mint shares to the buyer
IShare(ERC1155).shareMint(msg.sender, shareId, quantity);
emit Buy(shareId, msg.sender, quantity, buyPriceAfterFee);

// Deposit the buy price (in ETH) to the yield aggregator (e.g., Aave)
_safeTransferETH(address(yieldAggregator), buyPrice);
yieldAggregator.yieldDeposit();
Expand All @@ -239,10 +244,6 @@
if (refundAmount > 0) {
_safeTransferETH(msg.sender, refundAmount);
}

// Mint shares to the buyer
IShare(ERC1155).shareMint(msg.sender, shareId, quantity);
emit Buy(shareId, msg.sender, quantity, buyPriceAfterFee);
}

/**
Expand All @@ -256,7 +257,7 @@
uint32 quantity,
uint256 minETHAmount,
address referral
) public {
) public nonReentrant {
require(shareId < shareIndex, "Invalid shareId");
require(
IShare(ERC1155).shareBalanceOf(msg.sender, shareId) >= quantity,
Expand Down
Loading