Skip to content

Commit

Permalink
chore: lower referral fee to 2%
Browse files Browse the repository at this point in the history
  • Loading branch information
0xashu committed Jul 1, 2024
1 parent 415d3ec commit 686d969
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion contracts/core/SharesFactoryV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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
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

0 comments on commit 686d969

Please sign in to comment.