From 686d96951d86197be8615eba06d2f146a5c8c00c Mon Sep 17 00:00:00 2001 From: ashu Date: Mon, 1 Jul 2024 22:42:05 +0800 Subject: [PATCH] chore: lower referral fee to 2% --- contracts/core/SharesFactoryV1.sol | 2 +- test/unit/SharesFactory.t.sol | 39 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/contracts/core/SharesFactoryV1.sol b/contracts/core/SharesFactoryV1.sol index bb40e17..28dc50f 100644 --- a/contracts/core/SharesFactoryV1.sol +++ b/contracts/core/SharesFactoryV1.sol @@ -34,7 +34,7 @@ contract SharesFactoryV1 is Ownable2Step, ReentrancyGuard { uint256 public shareIndex; uint256 public depositedETHAmount; - uint256 public referralFeePercent = 5 * 1e16; + uint256 public referralFeePercent = 2 * 1e16; uint256 public creatorFeePercent = 5 * 1e16; uint256 public migrationDeadline; diff --git a/test/unit/SharesFactory.t.sol b/test/unit/SharesFactory.t.sol index f605b05..9cd1f80 100644 --- a/test/unit/SharesFactory.t.sol +++ b/test/unit/SharesFactory.t.sol @@ -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 - 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);