mvx_flash_loan_patterns_skill

This skill analyzes and enforces the atomic lend-execute-verify pattern, ensuring reentrancy guards, shard validation, and safe repayment in a single

10

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill multiversx/mx-ai-skills --skill mvx_flash_loan_patterns

  • SKILL.md2.3 KB

Overview

This skill describes a secure atomic lend-execute-verify pattern for MultiversX smart contracts. It focuses on performing a loan, calling a target callback, and verifying repayment inside one transaction while preventing common pitfalls. The pattern emphasizes reentrancy protection, shard validation, endpoint checks, and strict repayment verification.

How this skill works

Before sending funds, the contract verifies no operation is currently ongoing and that the target address is in the same shard. It sends the funds and invokes the provided callback in a single atomic call, then checks the contract balance to verify repayment plus fees. The guard flag is cleared at the end to allow future operations.

When to use it

  • Flash loans and temporary asset grants requiring atomic execution
  • Atomic swaps where loaned assets must be returned in the same transaction
  • Short-lived liquidity injections for arbitrage or on-chain composability
  • Never for cross-shard interactions or when async callbacks are acceptable

Best practices

  • Use a boolean reentrancy guard to block nested or concurrent operations
  • Validate that the target address is on the same shard to preserve atomicity
  • Reject built-in function callbacks and empty endpoints to avoid bypasses
  • Verify repayment by reading get_sc_balance after the callback, not storage mirrors
  • Always clear the guard flag in success and error paths to avoid lockouts

Example use cases

  • Provide a flash loan to an arbitrage bot that executes and repays within the same block
  • Perform an atomic token swap between two on-shard contracts with fee enforcement
  • Offer temporary liquidity for a contract to execute a tactical operation and return funds immediately
  • Run a grant-to-execute flow where repayment includes a predefined fee basis points

FAQ

Cross-shard calls execute in different blocks and lose atomicity, so repayment cannot be guaranteed within a single transaction.

Why check contract balance instead of a storage variable?

Storage values can be manipulated or not reflect token balances; get_sc_balance reads actual on-chain asset balance for reliable repayment verification.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
mvx_flash_loan_patterns skill by multiversx/mx-ai-skills | VeilStrat