Skip to content

Instantly share code, notes, and snippets.

@mrenoon mrenoon/DGX_fees.md
Last active Aug 8, 2018

Embed
What would you like to do?
DGX's fees calculation

DGX Token contract

Demurage fees

Overview

  • Demurrage fees can be turned off globally, exempting demurrage for all accounts. For the first one year, global demurrage is turned off
  • Demurrage fees can also be turned off for specific contracts/accounts

When is it deducted from an account A?

  • Before A recasts his DGX to a physical gold bar
  • Before A sends some DGX to another account
  • Before A receives some DGX from another account
  • Quarterly, a script will be run to deduct demurrage fees from all the accounts.

How is it calculated?

  • There are 2 global variables demurrage_base (default to 10000000) and demurrage_rate (default to 165)
  • Every account A has a value of last_demurrage_payment_timestamp (in seconds), which is initialized to be the current time when A first receives any DGXs
  • When a demurrage deduction occurs at current_time:
    • We calculate how many whole days have passed since the last_demurrage_payment_timestamp:
      days_elapsed = (current_time - last_demurrage_payment_timestamp) / ONE_DAY_DURATION_IN_SECONDS
      
    • The demurrage fees will be calculated as such:
      demurrage_fees = days_elapsed * user_balance * demurrage_rate / demurrage_base
      
    • We advance the last_demurrage_payment_timestamp by exactly days_elapsed:
      last_demurrage_payment_timestamp += days_elapsed * ONE_DAY_DURATION_IN_SECONDS
      
      As such, the new last_demurrage_payment_timestamp is not necessarily the current timestamp.
      • For example: if A's last_demurrage_payment_timestamp is 27 hours ago, then we will deduct A's demurrage for 1 day, and update his last_demurrage_timestamp to be 27 - 24 = 3 hours ago

Demurrage Calculator contract

  • This contract can be used by interested third-parties to calculate the demurrage on DGX: link to etherscan
function calculateDemurrage(uint256 _initial_balance, uint256 _days_elapsed)
           public
           view
           returns (uint256 _demurrage_fees, bool _no_demurrage_fees)
  • In the above function, the _demurrage_fees is the demurrage fees for a DGX balance of _initial_balance over a period of _days_elapsed days, if demurrage is turned on.
  • _no_demurrage_fees is true if global demurrage fees is currently turned off.

Demurrage and balanceOf of the DGX Token contract

  • The value returned by calling balanceOf of the DGX Token contract always takes into account the demurrage fees up until the current time, as if demurrage has just been deducted.

Transfer fees

Overview

  • Transfer fees can be turned off globally, for all accounts
  • Transfer fees can also be turned off for specific contracts/accounts
  • There is a minimum transfer amount (default to 0.001DGX)
  • A DGX transfer takes roughly 170000~220000 gas

How is it calculated and deducted

  • There are 2 global variables transfer_fees_base (default to 10000) and transfer_fees_rate (default to 13)
  • Transfer fees is calculated as such:
    transfer_fees = transfer_amount * transfer_fees_rate / transfer_fees_base 
    
  • When A transfers X DGXs to B, A's balance will be deducted X and B's balance will increase X - transfer_fees. transfer_fees will go to transfer_fee_collector's balance.

Token Config contract

All the configurations related to the DGX token (such as the demurrage_fees_base, demurrage_fees_rate, transfer_fees_base, transfer_fees_rate,...) can be read from this contract: link to etherscan

@sunny4hunny

This comment has been minimized.

Copy link

sunny4hunny commented May 15, 2018

what is maximum supply

@mrenoon

This comment has been minimized.

Copy link
Owner Author

mrenoon commented May 16, 2018

The total supply will keep increasing as more gold bars are put into the vault and the corresponding amount of DGXs is minted. Details about the current gold bars in the vault as well as the current supply of DGXs/gold bars can be checked at this link

@DiveInto

This comment has been minimized.

Copy link

DiveInto commented Aug 8, 2018

the contract seems really complicated, and it proxy most of it's function calls to other contracts, for example, the approve() function, it calls another contract(0xe8757A8bb02959FA2c2D778D0A4dD16E43cf5C5e), which we don't know the source code:

  function approve(address _spender, uint256 _value)
           public
           returns (bool success)
  {
    success = TokenApprovalController(get_contract(CONTRACT_CONTROLLER_TOKEN_APPROVAL)).approve(msg.sender, _spender, _value);
  }

don't get any reason why doing so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.