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

Pool: variable commission fee #393

Open
gangov opened this issue Nov 19, 2024 · 3 comments · May be fixed by #402
Open

Pool: variable commission fee #393

gangov opened this issue Nov 19, 2024 · 3 comments · May be fixed by #402
Assignees

Comments

@gangov
Copy link
Collaborator

gangov commented Nov 19, 2024

currently, the commission fee for the staking contract is set with as a hard % upon instantiating any pool. We should be using a variable percent for users that have staked (ideally, different tiers for the different staked amounts), so that way we incentivize our users.

@gangov gangov self-assigned this Nov 19, 2024
@gangov
Copy link
Collaborator Author

gangov commented Nov 29, 2024

we can use a simple formula that gives minimum swap fee based on the amount of staked tokens:

Swap Fee = Fmin + (Fmax−Fmin) × (C / (C+S))
where:
Fmax is the maximum fee percentage (e.g., 1% when no tokens were staked)
Fmin​ is the minimum fee percentage (e.g., 0.1% as the lowest possible fee).
C is the constant that determines how fast the fee decreases with increased staking (adjustable).
S is the amount of tokens the customer has staked.

a few examples:
user staked no tokens (S = 0): Swap Fee = 0.1% + 0.9% × (800 / (800 + 0)) = 1%
user staked 700 tokens (S = 700): Swap Fee = 0.1% + 0.9% × (800 / 1500) = 0.58%
user staked 800 tokens (S = 800): Swap Fee =0.1% + 0.9% × (800 / 1600) = 0.55%
user staked 1200 tokens (S = 1200): Swap Fee = 0.1% + 0.9% × (800 / 2000) = 0.46%

we can calculate this on each swap. The actual change can happen in the pool contract
where:

let compute_swap: ComputeSwap = compute_swap(
    &env,
    pool_balance_sell,
    pool_balance_buy,
    offer_amount,
    config.protocol_fee_rate(), // we change this input parameter to be calculated before this function call
    referral_fee_bps,
);

@gangov
Copy link
Collaborator Author

gangov commented Nov 30, 2024

'C' should be configurable by admin at any time. Ideally, we should somehow automatically adjust the value based on the staked amount in the pool(s)

@gangov gangov linked a pull request Dec 7, 2024 that will close this issue
@gangov
Copy link
Collaborator Author

gangov commented Dec 9, 2024

another approach to this problem would be if we actually use the staking contract and keep the variable fee in its storage. We can update the calculation whenever user does stake/unstake and then in pool just check for the %

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant