testnet
GitHub

OKRW Precompile

core external-dapp

Mint the native KRW-pegged stablecoin (OKRW) directly from your smart contracts.

The OKRW Precompile is a specialized, gas-efficient contract at a fixed address that exposes the core minting functionality of Maroo's native x/okrw module to the EVM. This allows developers to programmatically create new OKRW tokens, a crucial function for regulated financial applications, decentralized exchanges, and other protocols that need to manage stablecoin liquidity. The precompile enforces strict access control, ensuring only a designated minter account can create new tokens.

Key Features

EVM-Native Minting

Call a `mint` function from Solidity just like any other contract call, without needing complex cross-module communication.

Strict Access Control

Only the globally configured 'Minter Address' can successfully execute a mint, preventing unauthorized token creation.

Custom Error Reporting

Failed calls revert with detailed, custom Solidity errors (e.g., `UnauthorizedMinter`), allowing for robust off-chain and on-chain error handling.

Standard Event Emission

Emits a standard EVM `Mint` event, making it easy for indexers, block explorers, and dApps to track minting activity.

Architecture

graph TD
    subgraph EVM Environment
        A[Your Smart Contract] -->|calls IOkrw.mint(...)| B{OKRW Precompile<br>0x100...0001}
    end
    subgraph Cosmos SDK
        D[x/okrw Module] -->|updates balances| E[x/bank Module]
    end
    B -->|constructs & dispatches MsgMint| C(Maroo Message Router)
    C -->|routes message| D

Architectural flow of a call to the OKRW precompile. An EVM call is translated into a native Cosmos SDK message, processed by the `x/okrw` module, and results in a state change in the `x/bank` module.

How It Works

When a contract or EOA calls the mint function on the precompile's fixed address (0x100...0001), the Maroo node intercepts the call before it reaches the EVM. The precompile's Go implementation takes over, decoding the function arguments (recipient and amount).

The core logic then performs several crucial steps. First, it validates the inputs. Second, it retrieves the globally configured MinterAddress from the x/okrw module's parameters. It compares this address with contract.Caller(), which represents the direct caller of the precompile. If they do not match, the transaction is reverted. If they do match, the precompile constructs a native Cosmos SDK MsgMint. This message is then dispatched through Maroo's internal message router to the x/okrw module, which executes the final minting logic and updates the recipient's balance in the core x/bank module.
Note: The use of `contract.Caller()` is a deliberate security choice. It ensures that only direct calls to the precompile are permitted, preventing complex and potentially vulnerable call chains where one contract might try to mint on behalf of another.

Error and Event Handling

To provide a rich developer experience within the EVM, the precompile translates results from the Cosmos SDK layer into standard EVM constructs. If the x/okrw module returns an error (e.g., an authorization failure), the precompile's error-handling logic in errors.go packs this into a custom Solidity error revert. This is more gas-efficient and machine-readable than a simple string revert.

On a successful mint, the events.go logic constructs and emits a standard EVM log that matches the Mint event defined in the IOkrw interface. This allows dApp frontends, indexers, and other off-chain services to listen for and react to minting events just as they would with a standard ERC20 token.

Next Steps

Source: maroo
ESC
Type to search