FCTExt_TokensSafeMath

Smart contract that adds the ability to do basic math on values within FCT execution

The values ins and value out supports decimals, making it easy to support various ERC20 tokens.

For example is possible to add 2 USDC and 2 DAI although they use different decimals. The result of the calculation can be in any chosen decimals (one of the inputs or a different one).

MainFunctions

add

function add(
        uint256 amount1,
        uint256 decimals1,
        uint256 amount2,
        uint256 decimals2,
        uint256 decimalsOut
 )

sub

function sub(
        uint256 amount1,
        uint256 decimals1,
        uint256 amount2,
        uint256 decimals2,
        uint256 decimalsOut
 )

mul

function mul(
        uint256 amount1,
        uint256 decimals1,
        uint256 amount2,
        uint256 decimals2,
        uint256 decimalsOut
)

div

function div(
        uint256 amount1,
        uint256 decimals1,
        uint256 amount2,
        uint256 decimals2,
        uint256 decimalsOut
)

mulAndDiv

function mulAndDiv(
        uint256 amount1,
        uint256 decimals1,
        uint256 amount2,
        uint256 decimals2,
        uint256 amount3,
        uint256 decimals3,
        uint256 decimalsOut
)

Because the blockchain support only whole numbers, use mulAndDiv when there is a need to multiple a value by a fraction. For example: 1000 * 2.3 can be done by calculating 1000 * 23 / 10

Last updated