Main Contract
  • Introduction
  • Money on Chain platform
    • Main concepts
    • System states
    • Public actions
      • User actions
      • Process actions
    • Contracts architecture
      • MoC
      • CommissionSplitter
      • MoCState
      • MoCBucketContainer
      • MoCSettlement
      • MoCHelperLib
      • MoCLibConnection
      • MoCConverter
      • MoCExchange
      • MoCConnector
      • MoCBProxManager
      • MoCInrate
      • MoCVendors
      • MoCWhitelist
      • MoCBase
      • OwnerBurnableToken
      • BProToken
      • DocToken
      • MoCToken
      • PriceProvider
    • Contract mocks
    • Relevant patterns and choices
    • Data dictionary
    • Getting started
  • Integration with MoC platform
    • Introduction to MoC
      • The MoC Contract
      • MoC Precisions
      • MoC State Contracts
    • Getting BPros
      • Minting BitPros
      • Redeeming BitPros
    • Getting DoCs
      • Minting DoCs
      • Redeeming DoCs
        • On Settlement: redeemDocRequest
        • On Settlement: alterRedeemRequestAmount
        • Outside Settlement: redeemFreeDocVendors
        • On Liquidation State: redeemAllDoc
        • How-to
    • Commission fees values
    • Vendors
    • Fees calculation
    • From outside the blockchain
      • Using RSK nodes
      • Using web3
      • Official Money on Chain ABIs
      • Events
      • Example code minting BPros
      • Example code minting BPros without Truffle
      • Example code redeeming BPros
      • Example code redeeming BPros without Truffle
      • Example code minting DOC
      • Example code redeeming free DOC
      • Example code redeeming DOC Request
      • Example code redeeming all DOC
  • Smart contracts
    • Contracts verification
    • ABIs documentation
      • BProToken
      • BtcPriceProviderMock
      • DocToken
      • ERC20Mintable
      • Governed
      • Initializable
      • MakeStoppable
      • MakeUnstoppable
      • MoC
      • MoCBProxManager
      • MoCBucketContainer
      • MoCConnector
      • MoCConverter
      • MoCEMACalculator
      • MoCExchange
      • MoCHelperLib
      • MoCHelperLibMock
      • MoCInrate
      • MoCLibConnection
      • MoCPriceProviderMock
      • MoCSettlement
      • MoCSettlementMock
      • MoCState
      • MoCStateMock
      • MoCToken
      • MoCVendors
      • MoCWhitelist
      • MockMakeStoppable
      • MockMakeUnstoppable
      • MockStopper
      • MockUpgradeDelegator
      • MockUpgraderTemplate
      • OwnerBurnableToken
      • Pausable
      • PriceFeed
      • PriceFeederAdder
      • PriceFeederRemover
      • PriceProvider
      • RevertingOnSend
      • Stoppable
      • Stopper
      • UpgradeDelegator
      • UpgraderTemplate
Powered by GitBook
On this page
  1. Integration with MoC platform

Fees calculation

PreviousVendorsNextFrom outside the blockchain

Last updated 3 years ago

Fees (namely, commission and vendor markup) are a percentage of the amount of the transaction that will be charged for the usage of the platform. The sum of the commission and vendor markup will be at around 0.1% of the amount.

The calculation for the fees associated with the transaction is managed in the function calculateCommissionsWithPrices of the MoCExchange contract.

This function deals with all the parameters needed to calculate said fees. You will need to pass these parameters in the form of the CommissionParamsStruct struct:

struct CommissionParamsStruct{
  address account; // Address of the user doing the transaction
  uint256 amount; // Amount from which commissions are calculated
  uint8 txTypeFeesMOC; // Transaction type if fees are paid in MoC
  uint8 txTypeFeesRBTC; // Transaction type if fees are paid in RBTC
  address vendorAccount; // Vendor address
}

You must assign all the parameters to the struct before calling the function. Transaction types for every operation are explained . You must have an instance of the MoCInrate contract in order to access every valid transaction type.

Fees will be paid in MoC in case the user has MoC token balance and allowance; otherwise they will be paid in RBTC.

You will receive a CommissionReturnStruct struct in return with all the values calculated for you:

struct CommissionReturnStruct{
  uint256 btcCommission; // Commission in BTC if it is charged in BTC; otherwise 0
  uint256 mocCommission; // Commission in MoC if it is charged in MoC; otherwise 0
  uint256 btcPrice; // BTC price at the moment of the transaction
  uint256 mocPrice; // MoC price at the moment of the transaction
  uint256 btcMarkup; // Markup in BTC if it is charged in BTC; otherwise 0
  uint256 mocMarkup; // Markup in MoC if it is charged in BTC; otherwise 0
}

In conclusion:

  • If you are minting and fees are paid in RBTC, the amount sent to the transaction has to be at least the amount in BTC desired plus the commission (amount times the commission rate) plus the markup (amount times the vendor markup). If the operation involves interests, you should add them as well.

btcSent (msg.value) >= CommissionParamsStruct.amount + CommissionParamsStruct.amount * CommissionReturnStruct.btcCommission + CommissionParamsStruct.amount * CommissionReturnStruct.btcMarkup + interests

If fees are paid in MoC, then btcSent (msg.value) == CommissionParamsStruct.amount

  • If you are redeeming and fees are paid in RBTC, the transaction returns the amount in RBTC discounting the previously calculated fees. If the operation involves interests, you should subtract them as well.

totalBtc = <token>ToBtc(finalAmount);
btcReceived = totalBtc - totalBtc * CommissionReturnStruct.btcCommission - totalBtc * CommissionReturnStruct.btcMarkup - interests

If fees are paid in MoC, then btcReceived == CommissionParamsStruct.amount

here