anhdungle
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Gains network fee ## Oracle fee - Paid whenever the order is executed - Paid in function `getPrice()` in `GNSPriceAggregatorV6_4.sol` - Calculated by helper function `linkFee`, then distributed evenly amongst all participating oracle nodes ![](https://hackmd.io/_uploads/SkI8VolJ6.png) - Each pair has an oracle fee coefficient stored in `GNSPairsStorageV6.sol`, then multiplied of the leveraged position of the order, divided by the LINK price to get the total amount of LINK to pay. ![](https://hackmd.io/_uploads/SJ6Ursxka.png) - We cannot remove this fee, but maybe we can consider a fixed amount of LINK instead of the current dynamic one depending on the leveraged volume. ## Fixed spread - Paid for open market/limit orders - When the most recent price feed is submitted by the oracles through the function `fulfill()` in `GNSPriceAggregatorV6_4.sol`, the aggregator contract calls the function `openTradeMarketCallback` (for open market order) or the function `executeNftOpenOrderCallback` (for open limit order) in `GNSTradingCallbacksV6_4`. - Calculated by the function `marketExecutionPrice` in `GNSTradingCallbacksV6_4`. ![](https://hackmd.io/_uploads/BJsUHW-kT.png) - The input `price` is the open price submitted by the oracles - The input `spreadP` is stored in `GNSPairsStorageV6` and configured when the pair is added to the system by the governance. - The input `spreadReductionP` is baded on NFT tier ownership. - The price diff the then a percentage (`spreadP - spreadReductionP`) of the `price`, which is added to the `price` if the order is long or subtracted if the order is short. In both cases user's profit after closing the position is less by this amount. ## Dynamic spread - Taken on top of the fixed spread so it appears in the same places. - Calculated by the function `getTradePriceImpactPure()` in `GNSPairInfosV6_1`. ![](https://hackmd.io/_uploads/ryjgqZZJp.png) - The input `openPrice` is the price after considering fixed spread. - The input `long` is true for long orders and false for short orders. - The input `startOpenInterest` is the volume of all long (or short) trades for the pair. It is stored in `GFarmTradingStorage5`. - The input `tradeOpenInterest` is the leveraged volume of the current order. - The input `onePercentDepth` is from the trading activities from Binance and imported onchain to `GNSPairInfosV6_1` by the manager. - The bigger the current direction volume, i.e. asset utilization, the higher the price impact. The lower the `onePercentDepth`, i.e. illiquid pair, the higher the price impact. - Again the price impact is added to the `price` if the order is long or subtracted if the order is short. In both cases user's profit after closing the position is less by this amount. ## DevGovFee - Paid for open market/limit orders - Calculated in the function `registerTrade()` in `GNSTradingCallbacksV6_4`. ![](https://hackmd.io/_uploads/rkoE2sWya.png) - Calculated by the function `handleDevGoveFees` in `GFarmTradingStorage5`. ![](https://hackmd.io/_uploads/Syq8hoWJa.png) - Taken as a percentage of the leveraged position. The percentage is pair specific and stored in `GNSPairsStorageV6`. - The fees are claimed by the function `claimFees()` in `GFarmTradingStorage5`. ## Referral fee - Paid for open market/limit orders - Calculated in the function `registerTrade()` in `GNSTradingCallbacksV6_4`. ![](https://hackmd.io/_uploads/H1r9JfW1p.png) - The referral fee is a percentage of the open fee. This percentage is calculated by `getPercentOfOpenFeeP_calc()` in `GNSReferralsV6_2`. ![](https://hackmd.io/_uploads/B1bKis-ya.png) - Where `openFeeP` and `startReferrerFeeP` are two fixed constant - Note that this is taken from DevGovFee ## NFT fee - Paid for limit orders with spread reduction NFT - Calculated in the function `registerTrade(), executeNftCloseOrderCallback()` in `GNSTradingCallbacksV6_4`. ![](https://hackmd.io/_uploads/rJT4yh-ya.png) ## Staking fee - Paid for market orders or limit orders without spread reduction NFT - Calculated in the function `registerTrade(), unregisterTrade()` in `GNSTradingCallbacksV6_4`. ![](https://hackmd.io/_uploads/r11d1hZ16.png) ## Borrowing fee - Paid when closing a trade - Called in `unregisterTrade()` in `GNSTradingCallbacksV6_4`. - Calculated by `getTradeBorrowingFee` in `GNSBorrowingFeesV6_4`. ![](https://hackmd.io/_uploads/rymMhHH-6.png) - We consider two percentages, pairBorrowingFee and groupBorrowingFee, then take the larger of the two. ## NFT Bot fee - Paid for close limit order - Called in `executeNftCloseOrderCallback` in `GNSTradingCallbacksV6_4`. ![](https://hackmd.io/_uploads/SJr1zn-1p.png) - If it's liquidation, then flat rate 5%. If it's closing the trade then the percentage is taken from `GNSPairsStorageV6`. # Fees in Kwenta and adjustments for Gains system ## Gelato fees - Can be replaced by NFT bot fee in the Gains system ## Taker and maker fees - Seems to be taken when positions are created and based on the difference between the long and short open interest. - If there is more short open interests then short traders will become takers and subjected to taker fee, long traders will become makers and subjected to maker fee. - We can use this fee to replace fixed and dynamic spread in the gains system. The open interests are stored in variables "openInterestDai" in "GFarmTradingStorage5" and we will need to adjust the code in the function `fulfill()` in `GNSPriceAggregatorV6_4.sol`, i.e. when the oracle reports the current price used to open the position. ## Funding fee - LV denotes the volume of long positions - SV denotes the volume of short positions - s denotes the skew and is defined as `s = LV - SV` - f denotes the funding rate and is calculated as `df = dr/dt = c*skew`, normally we consider df as a daily rate (see example) where c is the constant factor, which in kwenta is set to 0.000003 - In practice, the effect of this change is that funding rates will continuously drift higher/lower in the presence of uncorrected position imbalances, creating a natural price discovery mechanism for funding rates while simultaneously smoothing out funding rate trajectories. - Another notable change is that with this mechanism, LPs would no longer exclusively earn funding (e.g. short skew + positive funding, LPs pay funding). - Instead, funding flows through LPs without gain or loss over time (i.e. can be mathematically shown that net funding earned by LPs over time is zero). - In Gains network the volume of long positions and short positions are stored in the variables "openInterestDai" in "GFarmTradingStorage5" and are updated regularly. ![](https://hackmd.io/_uploads/rkfC9Ss-T.png) - We will need to add variables to store the global skew, skew per short token and per long token. - We will then need to use these variables and change the calculation of `getTradeBorrowingFee` in `GNSBorrowingFeesV6_4`. - The fee will be charged when the position gets closed. - We also need to adjust to liquidation logics to incorporate this fee to force liquidation when necessary.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully