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

SwapFeeManager contract for managing Dex and Burn Fees #8

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

laruh
Copy link
Member

@laruh laruh commented Nov 21, 2024

The SwapFeeManager contract handles the management and distribution of Dex and burn fees. Key features include:

  1. Fee Distribution:

    • Splits the contract's balance (Ether or ERC20 tokens) into:
      • 75% for dexFeeWallet.
      • 25% for burnFeeWallet.
  2. Ether Management:

    • Accepts Ether deposits.
    • The splitAndWithdraw function splits and transfers the Ether to the designated wallets.
  3. ERC20 Token Management:

    • Supports ERC20 tokens via the splitAndWithdrawToken function, which similarly splits and transfers the token balance.
  4. Access Control:

    • Functions for splitting and withdrawing funds can only be called by the contract owner.
  5. Event Logging:

    • Emits a FeesSplit event whenever fees are split and distributed.

@laruh laruh assigned dimxy and shamardy and unassigned dimxy and shamardy Nov 25, 2024
@laruh laruh requested review from dimxy and shamardy November 25, 2024 08:19
Copy link

@mariocynicys mariocynicys left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! nice language :)

Comment on lines 41 to 42
expect(finalDexFeeBalance - initialDexFeeBalance).to.equal(ethers.parseEther("0.75"));
expect(finalBurnFeeBalance - initialBurnFeeBalance).to.equal(ethers.parseEther("0.25"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ummmm, why are we checking the balance difference and not just the new balance?

Copy link
Member Author

@laruh laruh Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before each test we get a set of default hardhat accounts, which have non-zero eth balances

accounts = await ethers.getSigners();

when you run tests, these accounts persist their state (including balance) across tests in the same testing session.

Initial ETH Dex Fee Wallet Balance: 10000000000000000000000
Initial ETH Burn Fee Wallet Balance: 10000000000000000000000
Final ETH Dex Fee Wallet Balance: 10000750000000000000000
Final ETH Burn Fee Wallet Balance: 10000250000000000000000
    ✔ should correctly split and withdraw Ether fees (61ms)
Initial ERC20 Dex Fee Wallet Balance: 0
Initial ERC20 Burn Fee Wallet Balance: 0
Initial ETH Dex Fee Wallet Balance: 10000750000000000000000
Initial ETH Burn Fee Wallet Balance: 10000250000000000000000
Final ERC20 Dex Fee Wallet Balance: 750000000000000000
Final ERC20 Burn Fee Wallet Balance: 250000000000000000
    ✔ should correctly split and withdraw ERC20 token fees (113ms)

As for Erc20 token, in log we see 0, as we dont transfer tokens manually to account as in these for example from EtomicSwapTakerV2.js

await token.transfer(accounts[1].address, ethers.parseEther('100'));

well, I can set balance to 0 with hardhat rpc 2af148a

uint256 totalBalance = address(this).balance;
require(totalBalance > 0, "No fees to split");

uint256 burnFeeAmount = (totalBalance * 25) / 100;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we set these percentages as const?

Copy link
Member Author

@laruh laruh Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep we can, as constants are fixed at compile-time it doesnt increase gas usage 2af148a

@laruh laruh force-pushed the fee_manager_contract branch from 4c0f115 to 2af148a Compare November 25, 2024 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants