multiversx-defi-math

Implement precision-safe rounding and percentage calculations for MultiversX DeFi contracts.

12|5|Updated Jan 28, 2026
One-click install
npx skills add https://github.com/multiversx/mx-ai-skills --skill multiversx-defi-math
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: multiversx-defi-math
Source: https://github.com/multiversx/mx-ai-skills/tree/main/skills/multiversx-defi-math
Command: npx skills add https://github.com/multiversx/mx-ai-skills --skill multiversx-defi-math

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the critical need for precise and safe financial calculations in DeFi smart contracts on MultiversX, preventing value leakage and exploitation due to rounding errors.

Core Features & Use Cases

  • Precision Management: Provides constants and guidance for choosing appropriate decimal precision (BPS, PPM, WAD, RAY).
  • Safe Rounding: Implements half-up rounding for unsigned and signed numbers to avoid systematic value loss.
  • Percentage Calculations: Offers utilities for fee calculations using framework's proportion() and manual BPS/PPM methods.
  • Use Case: When developing a lending protocol, use this Skill's RAY_PRECISION and half-up rounding for interest calculations to ensure accurate compounding and prevent protocol insolvency.

Quick Start

Use the multiversx-defi-math skill to calculate a 2.5% fee on a 1000 token amount.

Frequently Asked Questions about multiversx-defi-math

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent rounding errors in MultiversX DeFi smart contracts?

To prevent rounding errors in MultiversX DeFi smart contracts, implement half-up rounding and safe rescaling patterns for token math, which mitigates value leakage and rounding attack vectors.

What is the best way to calculate fees and percentages in MultiversX smart contracts?

The best way to calculate fees in MultiversX smart contracts is using BPS, PPM, WAD, or RAY precision constants alongside the framework's proportion() function or manual BPS/PPM methods for accurate percentage calculations.

When do I need safe rescaling for financial math in DeFi protocols?

You need safe rescaling for financial math in DeFi protocols when handling token math, fee calculations, or interest compounding to ensure accurate decimal precision management and prevent protocol insolvency.

Does MultiversX smart contract development require specific precision constants for interest calculations?

MultiversX smart contract development requires specific precision constants like RAY_PRECISION for interest calculations, ensuring accurate compounding in lending protocols and robust financial logic implementation.

Why does systematic value loss occur in DeFi token math and how can I mitigate it?

Systematic value loss occurs in DeFi token math due to improper rounding direction during rescaling; mitigate it by applying half-up rounding utilities for unsigned and signed numbers to secure arithmetic operations.