mvx_defi_math

Perform safe financial math with half-up rounding and RAY precision for MultiversX DeFi.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the critical need for accurate and secure financial calculations within decentralized finance (DeFi) applications on the MultiversX blockchain, preventing common vulnerabilities arising from precision loss and rounding errors.

Core Features & Use Cases

  • Precision Management: Defines and utilizes standard precision levels (BPS, PPM, WAD, RAY) for financial operations.
  • Safe Arithmetic: Implements half-up rounding for multiplication and division to prevent systematic value loss and potential exploits.
  • Secure Rescaling: Provides a safe method for converting values between different precision levels.
  • Percentage Calculations: Offers utilities for applying fees and percentages using BPS and PPM.
  • Use Case: When developing a lending protocol, use this Skill's RAY precision and half-up rounding for interest calculations to ensure fairness and prevent exploits.

Quick Start

Use the mvx_defi_math skill to calculate a 2.5% fee on a principal amount of 1000 WAD using half-up rounding.

Frequently Asked Questions about mvx_defi_math

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

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

Prevent rounding attacks in MultiversX DeFi smart contracts by applying half-up rounding for multiplication and division. This ensures safe arithmetic operations that stop systematic value loss and block potential exploitation vectors.

What precision levels should I use for financial math on MultiversX?

Use standard precision levels BPS, PPM, WAD, and RAY for financial math on MultiversX. Enforce RAY precision for intermediate calculations to prevent precision loss, and apply BPS or PPM specifically for fee calculations.

How do I calculate fees and percentages safely in a DeFi protocol?

Calculate fees and percentages safely in a DeFi protocol by applying BPS or PPM precision utilities. These methods securely apply percentages and enforce half-up rounding to ensure accurate fee distribution without value leakage.

How do I safely rescale values between different precision levels?

Safely rescale values between different precision levels by using a secure rescaling method. This prevents precision loss when converting values between WAD, RAY, BPS, and PPM standards during complex DeFi operations.

Do I need RAY precision for interest rate calculations in lending protocols?

You need RAY precision for interest rate calculations in lending protocols to maintain maximum accuracy. Using RAY for intermediate calculations combined with half-up rounding ensures fairness and prevents rounding exploits over time.

Why does precision loss occur in DeFi financial math and how to fix it?

Precision loss occurs in DeFi financial math due to anti-patterns in multiplication and division without proper scaling. Fix it by enforcing standard precision levels for intermediate steps and applying half-up rounding to secure the rescaling process.