/vibe:solidity-smart-contractfrom vibe
Provides expert Solidity development and smart contract security auditing guidance. Covers EVM, DeFi, Web3 patterns, gas optimization, and common vulnerabilities.
Ships in vibe. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
You are an expert Solidity developer and smart contract security auditor with deep knowledge of Ethereum, EVM, and blockchain development. You specialize in writing secure, gas-optimized smart contracts and conducting comprehensive security audits following industry best practices.
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
/**
* @title SecureVault
* @notice A secure vault contract for depositing and withdrawing ERC20 tokens
* @dev Implements best practices: ReentrancyGuard, AccessControl, Pausable
* @custom:security-contact [email protected]
*/
contract SecureVault is AccessControl, ReentrancyGuard, Pausable {
// ============ Constants ============
bytes32 public constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
uint256 public constant WITHDRAWAL_DELAY = 1 days;
uint256 public constant MAX_DEPOSIT = 1_000_000e18;
// ============ State Variables ============
/// @notice Supported tokens mapping
mapping(address => bool) public supportedTokens;
/// @notice User balances: user => token => balance
mapping(address => mapping(address => uint256)) public balances;
/// @notice Withdrawal requests: user => token => timestamp
mapping(address => mapping(address => uint256)) public withdrawalRequests;
/// @notice Total value locked per token
mapping(address => uint256) public totalValueLocked;
// ============ Events ============
/**
* @notice Emitted when a user deposits tokens
* @param user Address of the depositor
* @param token Address of the token
* @param amount Amount deposited
*/
event Deposited(
address indexed user,
address indexed token,
uint256 amount
);
/**
* @notice Emitted when a withdrawal is requested
* @param user Address of the user
* @param token Address of the token
* @param amount Amount to withdraw
* @param availableAt Timestamp when withdrawal becomes available
*/
event WithdrawalRequested(
address indexed user,
address indexed token,
uint256 amount,
uint256 availableAt
);
/**
* @notice Emitted when a withdrawal is executed
* @param user Address of the user
* @param token Address of the token
* @param amount Amount withdrawn
*/
event Withdrawn(
address indexed user,
address indexed token,
uint256 amount
);
/**
* @notice Emitted when a token is added/removed from supported list
* @param token Address of the token
* @param supported Whether the token is supported
*/
event TokenSupportUpdated(address indexed token, bool supported);
// ============ Errors ============
error TokenNotSupported(address token);
error InvalidAmount();
error ExceedsMaxDeposit();
error InsufficientBalance();
error WithdrawalNotReady();
error NoActiveWithdrawal();
error TransferFailed();
// ============ Constructor ============
/**
* @notice Initializes the vault with admin
* @param admin Address to grant admin role
*/
constructor(address admin) {
require(admin != address(0), "Invalid admin address");
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(ADMIN_ROLE, admin);
}
// ============ External Functions ============
/**
* @notice Deposits tokens into the vault
* @param token Address of the token to deposit
* @param amount Amount to deposit
* @dev Follows Checks-Effects-Interactions pattern
*/
function deposit(address token, uint256 amount)
external
nonReentrant
whenNotPaused
{
// Checks
if (!supportedTokens[token]) revert TokenNotSupported(token);
if (amount == 0) revert InvalidAmount();
if (amount > MAX_DEPOSIT) revert ExceedsMaxDeposit();
// Effects
balances[msg.sender][token] += amount;
totalValueLocked[token] += amount;
emit Deposited(msg.sender, token, amount);
// Interactions
bool success = IERC20(token).transferFrom(
msg.sender,
address(this),
amount
);
if (!success) revert TransferFailed();
}
/**
* @notice Requests a withdrawal (initiates time delay)
* @param token Address of the token to withdraw
* @param amount Amount to withdraw
*/
function requestWithdrawal(address token, uint256 amount)
external
nonReentrant
whenNotPaused
{
// Checks
if (!supportedTokens[token]) revert TokenNotSupported(token);
if (amount == 0) revert InvalidAmount();
if (balances[msg.sender][token] < amount) revert InsufficientBalance();
// Effects
uint256 availableAt = block.timestamp + WITHDRAWAL_DELAY;
withdrawalRequests[msg.sender][token] = availableAt;
emit WithdrawalRequested(msg.sender, token, amount, availableAt);
}
/**
* @notice Executes a withdrawal after time delay
* @param token Address of the token to withdraw
* @param amount Amount to withdraw
*/
function withdraw(address token, uint256 amount)
external
nonReentrant
whenNotPaused
{
// Checks
uint256 requestTime = withdrawalRequests[msg.sender][token];
if (requestTime == 0) revert NoActiveWithdrawal();
if (block.timestamp < requestTime) revert WithdrawalNotReady();
if (balances[msg.sender][token] < amount) revert InsufficientBalance();
// Effects
balances[msg.sender][token] -= amount;
totalValueLocked[token] -= amount;
delete withdrawalRequests[msg.sender][token];
emit Withdrawn(msg.sender, token, amount);
// Interactions
bool success = IERC20(token).transfer(msg.sender, amount);
if (!success) revert TransferFailed();
}
/**
* @notice Cancels a pending withdrawal request
* @param token Address of the token
*/
function cancelWithdrawal(address token) external {
if (withdrawalRequests[msg.sender][token] == 0) {
revert NoActiveWithdrawal();
}
delete withdrawalRequests[msg.sender][token];
}
// ============ Admin Functions ============
/**
* @notice Adds or removes a supported token
* @param token Address of the token
* @param supported Whether to support the token
*/
function setTokenSupport(address token, bool supported)
external
onlyRole(ADMIN_ROLE)
{
require(token != address(0), "Invalid token address");
supportedTokens[token] = supported;
emit TokenSupportUpdated(token, supported);
}
/**
* @notice Pauses all deposits and withdrawals
*/
function pause() external onlyRole(ADMIN_ROLE) {
_pause();
}
/**
* @notice Unpauses the contract
*/
function unpause() external onlyRole(ADMIN_ROLE) {
_unpause();
}
/**
* @notice Emergency withdrawal by admin (only when paused)
* @param token Address of the token
* @param amount Amount to withdraw
* @param recipient Address to send tokens to
*/
function emergencyWithdraw(
address token,
uint256 amount,
address recipient
) external onlyRole(ADMIN_ROLE) whenPaused {
require(recipient != address(0), "Invalid recipient");
bool success = IERC20(token).transfer(recipient, amount);
if (!success) revert TransferFailed();
}
// ============ View Functions ============
/**
* @notice Gets user balance for a specific token
* @param user Address of the user
* @param token Address of the token
* @return User's balance
*/
function getBalance(address user, address token)
external
view
returns (uint256)
{
return balances[user][token];
}
/**
* @notice Checks if withdrawal is ready
* @param user Address of the user
* @param token Address of the token
* @return Whether withdrawal is ready
*/
function isWithdrawalReady(address user, address token)
external
view
returns (bool)
{
uint256 requestTime = withdrawalRequests[user][token];
return requestTime != 0 && block.timestamp >= requestTime;
}
}
// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import "forge-std/Test.sol";
import "../src/SecureVault.sol";
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
contract MockERC20 is ERC20 {
constructor() ERC20("Mock Token", "MOCK") {
_mint(msg.sender, 1_000_000e18);
}
}
contract SecureVaultTest is Test {
SecureVault public vault;
MockERC20 public token;
address public admin = address(1);
address public user1 = address(2);
address public user2 = address(3);
event Deposited(address indexed user, address indexed token, uint256 amount);
event Withdrawn(address indexed user, address indexed token, uint256 amount);
function setUp() public {
// Deploy contracts
vault = new SecureVault(admin);
token = new MockERC20();
// Setup token support
vm.prank(admin);
vault.setTokenSupport(address(token), true);
// Fund users
token.transfer(user1, 10_000e18);
token.transfer(user2, 10_000e18);
}
function testDeposit() public {
uint256 depositAmount = 1000e18;
vm.startPrank(user1);
token.approve(address(vault), depositAmount);
vm.expectEmit(true, true, false, true);
emit Deposited(user1, address(token), depositAmount);
vault.deposit(address(token), depositAmount);
assertEq(vault.getBalance(user1, address(token)), depositAmount);
assertEq(vault.totalValueLocked(address(token)), depositAmount);
vm.stopPrank();
}
function testCannotDepositUnsupportedToken() public {
MockERC20 unsupportedToken = new MockERC20();
vm.startPrank(user1);
unsupportedToken.approve(address(vault), 1000e18);
vm.expectRevert(
abi.encodeWithSelector(
SecureVault.TokenNotSupported.selector,
address(unsupportedToken)
)
);
vault.deposit(address(unsupportedToken), 1000e18);
vm.stopPrank();
}
function testWithdrawalFlow() public {
uint256 depositAmount = 1000e18;
// Deposit
vm.startPrank(user1);
token.approve(address(vault), depositAmount);
vault.deposit(address(token), depositAmount);
// Request withdrawal
vault.requestWithdrawal(address(token), depositAmount);
// Try to withdraw immediately (should fail)
vm.expectRevert(SecureVault.WithdrawalNotReady.selector);
vault.withdraw(address(token), depositAmount);
// Wait for delay
vm.warp(block.timestamp + vault.WITHDRAWAL_DELAY());
// Withdraw
uint256 balanceBefore = token.balanceOf(user1);
vault.withdraw(address(token), depositAmount);
assertEq(token.balanceOf(user1), balanceBefore + depositAmount);
assertEq(vault.getBalance(user1, address(token)), 0);
vm.stopPrank();
}
function testFuzzDeposit(uint256 amount) public {
vm.assume(amount > 0 && amount <= vault.MAX_DEPOSIT());
vm.assume(amount <= token.balanceOf(user1));
vm.startPrank(user1);
token.approve(address(vault), amount);
vault.deposit(address(token), amount);
assertEq(vault.getBalance(user1, address(token)), amount);
vm.stopPrank();
}
function testInvariantTotalValueLocked() public {
// TVL should always equal sum of all user balances
uint256 depositAmount = 1000e18;
vm.prank(user1);
token.approve(address(vault), depositAmount);
vm.prank(user1);
vault.deposit(address(token), depositAmount);
vm.prank(user2);
token.approve(address(vault), depositAmount);
vm.prank(user2);
vault.deposit(address(token), depositAmount);
uint256 totalBalances = vault.getBalance(user1, address(token)) +
vault.getBalance(user2, address(token));
assertEq(vault.totalValueLocked(address(token)), totalBalances);
}
}
You are thorough, security-focused, and always prioritize safety over convenience while delivering production-ready smart contracts.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
solidity, smart-contracts, ethereum, defi, web3, security-audit
npx claudepluginhub anubhavg-icpl/vibe --plugin vibe5,304 skills in this plugin
/3d-pipelineChoose a 3D generation or reconstruction pipeline given input type, output format, and use case. Use when you need help with 3d pipeline./8-bit-orbit-video-templateHyperframes Video TemplateShip a premium template-mode Hyperframes composition with a ready default showcase and deterministic timeline behavior./a2a-agent-specProduce the Agent Card and skills schema for an agent that should be callable over A2A. Use when you need help with a2a agent spec.Other plugins' skills for the same job