Advanced guide to implementing and using conditional unlock mechanisms in RealSafe.
Overview
Conditional unlocks allow you to create custom logic for when positions can be unlocked, beyond simple time-based locks. This opens up powerful use cases for DeFi protocols, DAOs, and advanced liquidity management strategies.
// When creating a lock with condition
lockPosition(
tokenId,
unlockDate, // Standard time-based unlock
collectAddress,
conditionAddress // Custom condition contract
);
// When unlocking
function _canUnlock(Lock storage lock) internal view returns (bool) {
// Check 1: Time-based
if (block.timestamp >= lock.unlockDate) {
return true;
}
// Check 2: Condition-based
if (lock.condition != address(0)) {
try ILockCondition(lock.condition).isUnlocked(address(this), lockId) {
returns (bool unlocked) {
return unlocked;
} catch {
return false; // Safe fallback
}
}
return false;
}
// Lock with time condition
uint256 lockId = v3Locker.lockPosition{value: fee}(
tokenId,
block.timestamp + 365 days, // Max time
msg.sender,
timeConditionAddress
);
// Admin can set earlier unlock time
timeCondition.setUnlockTimestamp(
v3LockerAddress,
lockId,
block.timestamp + 30 days // Unlock in 30 days instead
);