All projects

VaultLink

VaultLink is a Chainlink-powered autonomous escrow contract that executes secure fund settlements triggered automatically by real-time market data or predefined time intervals.

CRE & AI

What it is

VaultLink.sol is a specialized smart contract designed to manage trustless, time-bound, and price-dependent escrow services. It removes the need for manual oversight by delegating state monitoring and execution logic to decentralized oracles.
Core Architectural Components
 * Autonomous Monitoring (Chainlink Automation):
  The contract integrates AutomationCompatibleInterface to enable off-chain monitoring. Instead of users manually triggering the release of funds, the contract exposes a checkUpkeep function. A decentralized network of Chainlink nodes continuously polls this function to determine if an escrow's time-lock has expired (releaseAt) or if a target asset price (PriceAtFirst) has been reached. When these conditions are met, the nodes automatically trigger performUpkeep to finalize the transaction.
 * Verified Data Feeds (Chainlink Price Feeds):
  To ensure that the price-based triggers are tamper-proof and accurate, the contract uses AggregatorV3Interface. It fetches live market prices from decentralized oracles. The implementation includes a robust normalization layer (getNormalizedPrice), which converts varied price feed decimal precisions (e.g., 8-decimal or 18-decimal) into a standardized 10^{18} format, preventing mathematical errors during threshold comparisons.
Gas Optimization Strategy
Standard escrow contracts often fail when scaling because they loop through an entire array of transactions, which consumes excessive "gas" and can cause the transaction to fail. VaultLink.sol addresses this with a pointer-based system:
 * The headIndex Pointer: Instead of iterating through all pending escrows, the contract maintains a headIndex. This acts as a bookmark, identifying the first active, non-processed escrow.
 * _advanceHead Mechanism: After any successful settlement (performUpkeep), this function scans forward to update the headIndex to the next unresolved item. This ensures that the computational cost of checking upkeep remains O(1) relative to the number of processed items, effectively preventing "Out of Gas" errors.
Security Model
The contract is hardened against common exploit vectors:
 * Checks-Effects-Interactions: The contract strictly updates the internal state (e.state = State.Released) before invoking external calls to transfer funds. This is the primary defense against reentrancy attacks.
 * Access Control: The system utilizes OpenZeppelin’s AccessControl and Pausable modules. This provides the administrator with the ability to pause the contract in the event of an emergency or vulnerability discovery, without compromising the locked funds.

How it Works

The VaultLink.sol project was engineered as a robust state-machine, moving away from simple linear scripts to a lifecycle-based architecture. This approach ensures that funds are locked, monitored, and transferred only when strict, verified conditions are met.
Core Architecture and State Management
The foundation of the contract is built around the Escrow struct, which encapsulates the entire lifecycle of a transaction. By utilizing an enum to track the State (None, Funded, Released, Refunded), the contract enforces rigid logic where funds can only be moved through authorized state transitions. This prevents unauthorized access or double-spending. Security is maintained by inheriting from industry-standard libraries, specifically using ReentrancyGuard to block reentrancy attacks and AccessControl for granular administrative permissions.
Oracle Integration and Data Normalization
The project acts as a bridge between off-chain market conditions and on-chain assets. It integrates the AggregatorV3Interface to interact with decentralized oracle networks for reliable pricing. A critical engineering step involved building a custom normalization layer. Because different price feeds often return varying decimal precisions, the contract includes a math layer to convert incoming data to a standardized 10^{18} format. This ensures that the price-trigger logic remains mathematically accurate regardless of the underlying data source.
Automation Engine
The "autonomous" behavior is achieved by implementing AutomationCompatibleInterface, which separates the logic into two distinct phases. The "Check" phase acts as an off-chain monitor, where the checkUpkeep function (a view function) consumes no gas while scanning the array for ready-to-settle escrows. The "Perform" phase, executed via performUpkeep, only runs on-chain when the conditions are strictly validated. This pattern offloads the heavy computational work to the off-chain network, keeping the contract efficient.
Gas Optimization Strategy
A major challenge in escrow contracts is scalability. Standard designs often iterate through the entire list of transactions, which leads to "Out of Gas" errors as the contract grows. VaultLink solves this with a pointer-based system.
Instead of looping through every escrow, the contract maintains a headIndex. This acts as a bookmark, identifying the first active, non-processed escrow. When a settlement occurs, the _advanceHead function scans forward to update the pointer. This keeps the computational complexity at O(1), meaning the gas cost for settling an escrow remains constant regardless of whether there are ten or ten thousand transactions in the queue.
By combining state-machine rigidity with off-chain automation and pointer-based gas efficiency, the project ensures a scalable, secure, and trustless experience for financial settlements.

Links

Created by

  • Mohammad