Comments (6)
Nex-Dex-Contracts/contracts/Exchange.sol
Lines 523 to 528 in 47b955c
Nex-Dex-Contracts/contracts/Exchange.sol
Line 531 in 47b955c
Nex-Dex-Contracts/contracts/Exchange.sol
Line 539 in 47b955c
I added the condition that if one side doesn't exist, the funding function will not run. Also, the funding fee will be according to the real trader's assetSize. For example, if index price is more than oracle price, we calculate the funding fee according to the all active short asset size and change the price to give this reward to long users(by decrease the vusd pool and decreasing the vBayc pool (by fixed k)
from nex-dex-contracts.
I not sure about the following:
If I open a long worth $10K and after me a short opens for $1K,
so now the pool price is allowed to move according to the funding rate.
Lets say the pool moves up 10% in price, so now the long is at a $11K, and the short is down to
This is not possible since the losses needs to cancel out the profits.
If we say, well then the short goes to zero, then they cancel out, but that would mean the short is suddenly 10x leveraged because the long position size was bigger.
Therefore, I think it is not possible not move the pool price (unless long and short are exactly the same size).
Another idea therefore might be: charge users the fundFee so they are incentivised to move the pool.
However, whenever they want to exit or get liquididated they are also charged their part of the fundFee,
so that if we have 10K users, they are all billed for 1/10.000 (1/activeUsers.length) gas fee per fundrate round .
from nex-dex-contracts.
In current code, I always calculate the fund fee by loser's position size.
By your example. Long worth 10K and short worth 1K.
If funding rate is +10%(indexPrice > oraclePrice), So funding fee will be calculte according to the worth of short positions (fundingFee = 10%*1K= 100);
If funding rate is -10%(indexPrice < oraclePrice), So funding fee will be calculte according to the worth of long positions (fundingFee = 10%*10K= 1000);
So always, funding fee will be according to the loser asset size.
If we have 1000K long and only 1K short and funding rate is positive, losers are long users and the funding fee is based on long user's asset size. If funding rate is negative, losers are short users and funding fee is based on short user's asset size. So funding fee is always based on the loser assetSize(1000K-10%*1000K or 1K - 10%1K)
from nex-dex-contracts.
"In current code, I always calculate the fund fee by loser's position size."
Good to know and I do not want to calculate the funding fee like this, it has to be relative to people their position size and just as an incentive without actually moving the pool price.
You can't touch the pool price (unless you can convince me otherwise), cause it can create net positive/negative profit and this is a zero sum game.
from nex-dex-contracts.
Nex-Dex-Contracts/contracts/Exchange.sol
Lines 844 to 882 in c7b8a41
I edited the function, so each user will have the funding fee effect in the collateral.
from nex-dex-contracts.
💯
from nex-dex-contracts.
Related Issues (20)
- oracle price split into TWAPoracle and liveOracle
- unintuitive sign HOT 2
- staying closer to the source code not to introduce an extra variable HOT 4
- What happens if user request zero withdrawal? HOT 4
- Why are you leaving 0.1? HOT 5
- add uniswap minimum amount out. HOT 3
- Could you type these functions out for me HOT 3
- Insurancefund = Liquidator? HOT 1
- Upper bound is bit high HOT 1
- Silver (and Gold probably same) contract price details HOT 1
- limit gas costs for setFundingRate by max users and min collateral deposit HOT 1
- Reduce fundingrate gas costs
- vulnerability report HOT 2
- Maximum call frequency setFundingRate HOT 3
- Cross contract collateral for hedged positions HOT 3
- Chainlink vrf HOT 3
- replace all BAYC and insurance refererences
- remove example contract warning HOT 1
- Before vulnerability report make overview smart contract vulnerability scanners
- Write article about wrapping staked tokens
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nex-dex-contracts.