Posts

What Makes a DeFi Lending Position Eligible for Liquidation?

Image
In DeFi lending, liquidation is not triggered simply because an asset loses market value. Protocols continuously evaluate the relationship between deposited collateral and outstanding debt to determine whether a borrower's position still meets the required safety conditions. This process depends on several interconnected components, including price oracles, interest calculations, collateral thresholds, and smart contract logic. How Protocols Evaluate Borrowing Risk Consider a borrower who deposits 2 ETH as collateral and takes a loan of 4,000 USDC. When ETH trades at $4,000, the deposited collateral is worth $8,000, providing sufficient backing for the loan. However, if ETH drops to $2,500, the collateral value falls to $5,000. The debt remains close to $4,000, although accrued interest may increase the amount owed. The protocol must recalculate the position and check whether it remains within its permitted risk limits. One important metric used in this process is Loan-to-Value (...

What Actually Happens When Two Blockchains Exchange a Message?

Image
  Blockchains can operate independently, but applications increasingly need to communicate across different networks. A smart contract on Ethereum, for example, cannot directly call a contract on another blockchain. Each network maintains its own state, execution environment, and consensus rules. This creates an important engineering challenge: how can one blockchain send instructions to another and ensure they are processed correctly? Cross-chain messaging addresses this problem by allowing applications to transmit data and instructions between blockchain networks. However, transferring a message is only one part of the process. The receiving chain must also establish that the message came from a legitimate source and has passed the required verification checks. Following a Message Across Two Blockchains Consider an application that needs to trigger a function on a destination blockchain. The process begins when a user interacts with a smart contract on the source chain. The sourc...

Inside Upgradeable Smart Contracts: How Storage Bugs and Proxy Risks Threaten Security

Image
A new implementation has been deployed to a proxy contract. The transaction succeeded, but users are reporting incorrect deposit balances. The previous implementation worked correctly, and the new code passes compilation. For a blockchain developer, this is a situation where checking the latest code alone may not reveal the cause. The investigation needs to cover how the new implementation interacts with the state already stored on-chain. Start With the Storage Layout Consider a simplified vault from its first release: contract VaultV1 {     address public owner;     mapping(address => uint256) public balances; } Now imagine the next release introduces a counter: contract VaultV2 {     address public owner;     uint256 public totalDeposits;     mapping(address => uint256) public balances; } The new variable occupies a storage slot that previously belonged to the mapping declaration....

How to Design Scalable Prediction Market Infrastructure

Image
  A prediction market may look simple on the surface: users trade on an outcome, an oracle determines what happened, and winners receive the payout. But building the infrastructure behind those steps is far more complex. A production-grade prediction market brings together trading engines, liquidity systems, smart contracts, oracle infrastructure, settlement logic, blockchain networks, indexers, APIs, and security controls . One of the most important architectural decisions is determining what should run on-chain, what should remain off-chain, and where trust needs to be enforced . What Does the Architecture Look Like? A typical prediction-market infrastructure can be divided into several layers: Application Layer – Handles users, markets, portfolios, and business logic. Trading Layer – Supports CLOBs, AMMs, order matching, and execution. Liquidity Layer – Maintains market depth and reduces slippage. Settlement Layer – Converts finalized outcomes into payouts. Smart Contracts ...

Limit vs Market Orders: What Actually Happens Inside an Order Book

Image
When a trader clicks Buy or Sell on a crypto exchange, the transaction may look instant, but several systems work behind the scenes. The order is validated, sent to the matching engine, checked against available liquidity, and eventually executed and settled. The type of order plays an important role in how this process works. Limit Orders: Price Control A limit order allows traders to specify the price at which they are willing to buy or sell. If a matching order is not available, the order can remain in the order book until it is filled, canceled, or expires. This gives traders greater price control , but execution is not guaranteed. A limit order can be fully filled, partially filled, or remain unfilled depending on market conditions and liquidity. Market Orders: Execution Priority A market order does not specify a fixed execution price. Instead, it is matched against the best available liquidity in the order book. For larger orders, the matching engine may consume liquidity acr...

How Smart Contract Events Work on EVM Blockchains

Image
  A smart contract can execute a token transfer, create an order, mint an NFT, or process a deposit in seconds. But how does an application know that one of these actions actually happened? Reading the entire blockchain state after every transaction would be inefficient. Instead, EVM-based smart contracts can emit events that record important actions as blockchain logs. Applications, indexers, analytics platforms, and backend services can then monitor these logs and respond to specific activities. Understanding smart contract events is therefore important for developers building applications on Ethereum and other EVM-compatible blockchains. This article explains how Solidity events work, how the EVM stores them, how indexed parameters are used, and how applications consume event data. What Are Smart Contract Events? A smart contract event is a mechanism used to record that a particular action occurred during contract execution. In Solidity, developers define an event with the eve...