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
  • Parameters of the operation
  • The docAmount parameter
  • The vendorAccount parameter
  • Gas limit and gas price
  • Possible failures
  • The contract is paused:
  • The MoC contract is in protected mode:
  • The MoC contract is liquidated:
  • Not enough gas:
  1. Integration with MoC platform
  2. Getting DoCs
  3. Redeeming DoCs

Outside Settlement: redeemFreeDocVendors

PreviousOn Settlement: alterRedeemRequestAmountNextOn Liquidation State: redeemAllDoc

Last updated 3 years ago

function redeemFreeDocVendors(uint256 docAmount, address vendorAccount) public

Redeems the requested docAmount for the user or the max amount of free docs possible if docAmount is bigger than max.

NOTE: there is a retrocompatibility function called redeemFreeDoc(uint256 docAmount) which is suitable for those who are already integrated to MoC platform and are not ready to use vendor functionality. In the future we are planning to deprecate this method.

Parameters of the operation

The docAmount parameter

It is the amount that the contract will use to redeem free DOCs. This parameter uses a precision of the type reservePrecision that contains 18 decimal places and is defined in MoCLibConnection contract.

The vendorAccount parameter

It is the address of the vendor who will receive a from the current transaction.

Money on Chain is a dynamic system that allows you to redeem a maximum amount of free DOCS and can be obtained by calling the freeDoc() view of the MocState contract.

The first part transforms the amount docAmount into an RBTC amount, but 3 things can happen:

  • If the absolute maximum amount of allowed DOCs is bigger than the user's balance in DOCs, then the user's total balance will be used to transform it to RBTC.

docAmountToRedeem = Math.min(mocState.freeDoc(), docToken.balanceOf(account));
  • If the previous amount is greater than the docAmount value, then docAmount will be used to transform it to RBTC.

finalDocAmount = Math.min(docAmount, docAmountToRedeem );
  • If none of the above conditions are met, docAmount will be used to transform it to RBTC.

docsBtcValue <= docsToBtc(finalDocAmount);

The second part will be used to compute and pay the interests of the operation that depends on the abundance of DOCs in the MOC system. The value can be obtained by invoking the function calcDocRedInterestValues(finalDocAmount, docsBtcValue) of the contract MocInrate and also has an accuracy of 18 decimal places.

The fifth part returns the amount in RBTC discounting the previously calculated fees and interests.

Gas limit and gas price

These two values are a parameter of the transaction, this is not used in the contract and is generally managed by your wallet (you should read about them if you are developing and do not know exactly what they are), but you should take them into account when trying to redeem some DOCs.

Possible failures

This operation may fail if one of the following scenarios occurs:

The contract is paused:

The MoC contract is in protected mode:

The MoC contract is liquidated:

In the extraneous case where a coverage that barely covers the stable tokens funds is reached, the contract will liquidate all of its assets. If this state occurs, no more DOCs will be available for minting. To know if the contract is liquidated you can ask the MocState for the state, this will return a 0 if liquidated (it is actually an enum).

Not enough gas:

If the gas limit sent is not enough to run all the code needed to execute the transaction, the transaction will revert (again, returning all your funds except the fee paid to the network). This may return an "out of gas" error or simply a "revert" error because of the usage of the proxy pattern.

The third part will be used to pay the commission, this part is a percentage of the previous part. The commission fees are explained in section.

The fourth part corresponds to the vendor markup, which refers to the fee a vendor will receive from this transaction and is a percentage of the first part. The vendor markup is explained in section.

All the needed calculations for the third and fourth parts are explained in more detail .

If the system suffers some type of attack, the contract can be paused so that operations cannot be done and the risk of the users losing their funds with the operation can be minimized. The condition is the same as that explained in .

In case global coverage falls below the protected threshold, the contract will enter the protected mode. If this state occurs, no more RDOCs will be available for minting. You can find more information about this mode .

this
here
here
The MoC contract is paused
markup
this