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

feedback/audit #34

Merged
merged 10 commits into from
Jul 2, 2024
2 changes: 1 addition & 1 deletion contracts/core/SharesFactoryV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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";
Expand Down Expand Up @@ -34,7 +34,7 @@

uint256 public shareIndex;
uint256 public depositedETHAmount;
uint256 public referralFeePercent = 5 * 1e16;
uint256 public referralFeePercent = 2 * 1e16;
uint256 public creatorFeePercent = 5 * 1e16;
uint256 public migrationDeadline;

Expand Down Expand Up @@ -88,7 +88,7 @@
}

function getSubTotal(uint32 fromSupply, uint32 quantity, uint8 curveType) public view returns (uint256) {
(uint96 basePrice, uint32 inflectionPoint, uint128 inflectionPrice, uint128 linearPriceSlope,) = getCurve(curveType);

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

View workflow job for this annotation

GitHub Actions / lint (18)

Line length must be no more than 123 but current length is 125

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

View workflow job for this annotation

GitHub Actions / lint (18)

Line length must be no more than 123 but current length is 125
return _subTotal(fromSupply, quantity, basePrice, inflectionPoint, inflectionPrice, linearPriceSlope);
}

Expand Down
39 changes: 25 additions & 14 deletions test/unit/SharesFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,47 +68,58 @@ contract SharesFactoryTests is BaseTest {
uint256 aliceBalBefore = addrAlice.balance;
uint256 bobBalBefore = addrBob.balance;
uint256 referrerBalBefore = referralReceiver.balance;
// uint256 factoryBalBefore = aWETH.balanceOf(address(sharesFactory));
uint256 depositedETHAmountBefore = sharesFactory.depositedETHAmount();

(
uint256 buyPriceAfterFee,
uint256 buyPrice,
uint256 referralFee,
uint256 creatorFee
) = sharesFactory.getBuyPriceAfterFee(0, 1, referralReceiver);
_buyShare(addrBob, 0, 1, referralReceiver);

uint256 aliceBalAfter = addrAlice.balance;
uint256 bobBalAfter = addrBob.balance;
uint256 referrerBalAfter = referralReceiver.balance;
// uint256 factoryBalAfter = aWETH.balanceOf(address(sharesFactory));
uint256 depositedETHAmountAfter = sharesFactory.depositedETHAmount();

assertEq(bobBalBefore - bobBalAfter, 5500450999999993); // Bob buy 1 share
0xashu marked this conversation as resolved.
Show resolved Hide resolved
assertEq(aliceBalAfter - aliceBalBefore, 250020499999999); // Alice receive creator fee
assertEq(referrerBalAfter - referrerBalBefore, 250020499999999); // referral receive fee
// assertEq(factoryBalAfter - factoryBalBefore, 5000409999999995); // Factory aWETH balance with rounding error
assertEq(depositedETHAmountAfter - depositedETHAmountBefore, 5000409999999995); // Factory records ETH Amount
assertEq(bobBalBefore - bobBalAfter, buyPriceAfterFee); // Bob buy 1 share
assertEq(aliceBalAfter - aliceBalBefore, creatorFee); // Alice receive creator fee
assertEq(referrerBalAfter - referrerBalBefore, referralFee); // referral receive fee
assertEq(depositedETHAmountAfter - depositedETHAmountBefore, buyPrice); // Factory records ETH Amount

uint256 bobShareBal = sharesNFT.balanceOf(addrBob, 0);
assertEq(bobShareBal, 2);
}

function test_buyShareWithHighVolume() public view {
(uint256 buyPriceAfterFee,,,) = sharesFactory.getBuyPriceAfterFee(0, 100000, referralReceiver);
console.log("test_buyShareWithHighVolume", buyPriceAfterFee);
}

function test_sellShares() public {
uint256 aliceBalBefore = addrAlice.balance;
uint256 bobBalBefore = addrBob.balance;
uint256 referrerBalBefore = referralReceiver.balance;
// uint256 factoryBalBefore = aWETH.balanceOf(address(sharesFactory));
uint256 depositedETHAmountBefore = sharesFactory.depositedETHAmount();

(
uint256 sellPriceAfterFee,
uint256 sellPrice,
uint256 referralFee,
uint256 creatorFee
) = sharesFactory.getSellPriceAfterFee(1, 1, referralReceiver);
_sellShare(addrAlice, 1, 1, referralReceiver);

uint256 aliceBalAfter = addrAlice.balance;
uint256 bobBalAfter = addrBob.balance;
uint256 referrerBalAfter = referralReceiver.balance;
// uint256 factoryBalAfter = aWETH.balanceOf(address(sharesFactory));
uint256 depositedETHAmountAfter = sharesFactory.depositedETHAmount();

assertEq(aliceBalAfter - aliceBalBefore, 4500163999999998); // Alice sell 1 share
assertEq(bobBalAfter - bobBalBefore, 250009111111111); // Bob receive creator fee
assertEq(referrerBalAfter - referrerBalBefore, 250009111111111); // Referral receive fee
// assertEq(factoryBalBefore - factoryBalAfter, 5000182222222220); // Factory aWETH balance with rounding error
assertEq(depositedETHAmountBefore - depositedETHAmountAfter, 5000182222222220); // Factory records ETH Amount
assertEq(aliceBalAfter - aliceBalBefore, sellPriceAfterFee); // Alice sell 1 share
assertEq(bobBalAfter - bobBalBefore, creatorFee); // Bob receive creator fee
assertEq(referrerBalAfter - referrerBalBefore, referralFee); // Referral receive fee
assertEq(depositedETHAmountBefore - depositedETHAmountAfter, sellPrice); // Factory records ETH Amount

uint256 aliceShareBal = sharesNFT.balanceOf(addrAlice, 1);
assertEq(aliceShareBal, 0);
Expand Down
Loading