RoC Stable Platform - Collateral RIF Token
  • Introduction
  • RIF 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
      • MoCRiskProxManager
      • MoCInrate
      • MoCVendors
      • MoCWhitelist
      • MoCBase
      • OwnerBurnableToken
      • RiskProToken
      • StableToken
      • MoCToken
      • PriceProvider
    • Contract mocks
    • Relevant patterns and choices
    • Data dictionary
    • Getting started
  • Integration with RoC platform
    • Introduction to RoC
      • The MoC Contract
      • RoC Precisions
      • RoC State Contracts
    • Getting RIFPros
      • Minting RIFPros
      • Redeeming RIFPros
    • Getting USDRIF
      • Minting USDRIF
      • Redeeming USDRIF
        • On Settlement: redeemStableTokenRequest
        • On Settlement: alterRedeemRequestAmount
        • Outside Settlement: redeemFreeStableToken
        • On Liquidation State: redeemAllStableToken
        • How-to
    • Commission fees values
    • Vendors
    • Fees calculation
    • From outside the blockchain
      • Using RSK nodes
      • Using web3
      • Official RIF On Chain ABIs
      • Events
      • Example code minting RIFPros
      • Example code minting RIFPros without Truffle
      • Example code redeeming RIFPros
      • Example code redeeming RIFPros without Truffle
      • Example code minting USDRIF
      • Example code redeeming free USDRIF
      • Example code redeeming USDRIF Request
      • Example code redeeming all USDRIF
  • Smart contracts
    • Contracts verification
    • ABIs documentation
      • Blockable
      • Blocker
      • ERC20Mintable
      • Governed
      • Initializable
      • MakeStoppable
      • MakeUnstoppable
      • MoC
      • MoCBucketContainer
      • MoCConnector
      • MoCConverter
      • MoCEMACalculator
      • MoCExchange
      • MoCHelperLib
      • MoCHelperLibMock
      • MoCInrate
      • MoCInrateRiskproxChanger
      • MoCLibConnection
      • MoCPriceProviderMock
      • MoCReserve
      • MoCRiskProxManager
      • MoCSettlement
      • MoCSettlementMock
      • MoCState
      • MoCStateMock
      • MoCToken
      • MoCVendors
      • MoCWhitelist
      • MocInrateStableChanger
      • MockBlocker
      • MockMakeStoppable
      • MockMakeUnstoppable
      • MockStopper
      • MockUpgradeDelegator
      • MockUpgraderTemplate
      • OwnerBurnableToken
      • Pausable
      • PriceFeed
      • PriceFeederAdder
      • PriceFeederRemover
      • PriceProvider
      • PriceProviderChanger
      • PriceProviderMock
      • ReserveToken
      • RiskProToken
      • StableToken
      • Stoppable
      • Stopper
      • UpgradeDelegator
      • UpgraderTemplate
Powered by GitBook
On this page
  1. Integration with RoC 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 txTypeFeesReserveToken; // Transaction type if fees are paid in RIF
  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 RIF.

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

struct CommissionReturnStruct{
  uint256 reserveTokenCommission; // Commission in RIF if it is charged in RIF; otherwise 0
  uint256 mocCommission; // Commission in MoC if it is charged in MoC; otherwise 0
  uint256 reserveTokenPrice; // RIF price at the moment of the transaction
  uint256 mocPrice; // MoC price at the moment of the transaction
  uint256 reserveTokenMarkup; // Markup in RIF if it is charged in RIF; otherwise 0
  uint256 mocMarkup; // Markup in MoC if it is charged in RIF; otherwise 0
}

In conclusion:

  • If you are minting and fees are paid in RIF, the amount sent to the transaction has to be at least the amount in RIF 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.

rifSent (msg.value) >= CommissionParamsStruct.amount + CommissionParamsStruct.amount * CommissionReturnStruct.reserveTokenCommission + CommissionParamsStruct.amount * CommissionReturnStruct.reserveTokenMarkup + interests

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

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

totalRif = <token>ToResToken(finalAmount);
rifReceived = totalRif - totalRif * CommissionReturnStruct.reserveTokenCommission - totalRif * CommissionReturnStruct.reserveTokenMarkup - interests

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

here