Contract Events
The EmeraldVault contract emits events for all significant state changes. These are useful for building indexers, notifications, or real-time dashboards.
Core Events
Deposit
Emitted when a user deposits assets into the vault.
event Deposit(
address indexed sender,
address indexed owner,
uint256 assets,
uint256 shares
);
| Field | Description |
|---|---|
sender | Address that initiated the deposit |
owner | Address that received the shares |
assets | Amount of underlying tokens deposited |
shares | Amount of vault shares minted |
WithdrawalRequested
Emitted when a user requests a withdrawal.
event WithdrawalRequested(
address indexed user,
uint256 indexed requestIndex,
uint256 shares,
uint256 assetsEstimate
);
| Field | Description |
|---|---|
user | Address requesting withdrawal |
requestIndex | Index in the withdrawal queue |
shares | Shares locked for this withdrawal |
assetsEstimate | Estimated assets at request time (recomputed at payout) |
WithdrawalInstant
Emitted when a withdrawal settles immediately (vault liquid, no queue backlog) — no requestIndex because nothing is queued.
event WithdrawalInstant(address indexed user, uint256 shares, uint256 assetsOwed);
WithdrawalReleased
Emitted when a queued withdrawal is paid out — by an admin batch release (releaseWithdrawals) or by the user self-claiming at the queue head (claimWithdrawal).
event WithdrawalReleased(
address indexed user,
uint256 indexed requestIndex,
uint256 shares,
uint256 assetsOwed
);
WithdrawalCancelled
Emitted when a user cancels their pending withdrawal.
event WithdrawalCancelled(
address indexed user,
uint256 indexed requestIndex,
uint256 shares
);
NAVUpdated
Emitted when the admin updates the off-chain managed assets.
event NAVUpdated(
uint256 oldManagedAssets,
uint256 newManagedAssets,
uint256 pricePerShare
);
| Field | Description |
|---|---|
oldManagedAssets | Previous managed assets value |
newManagedAssets | New managed assets value |
pricePerShare | Updated price per share after the NAV change |
Swept
Emitted when assets are swept to the omnibus wallet.
event Swept(
address indexed omnibus,
uint256 amount
);
VaultFunded
Emitted when the admin funds the vault (returns assets for withdrawals).
event VaultFunded(
address indexed from,
IERC20 indexed token,
uint256 amount
);
ReferralDeposit / ReferralWithdrawal
Emitted in addition to the standard event when a deposit or withdrawal carries a non-zero partnerId. Partners subscribe to these (filtered by partnerId) to track their referred activity.
event ReferralDeposit(
address indexed sender,
address indexed receiver,
uint256 assets,
uint256 shares,
uint256 partnerId
);
event ReferralWithdrawal(
address indexed user,
uint256 indexed requestIndex,
uint256 shares,
uint256 assetsEstimate,
uint256 partnerId
);
Standard Events
Transfer (ERC20)
Emitted on every share transfer, mint, and burn.
event Transfer(address indexed from, address indexed to, uint256 value);
- Mint:
from = 0x0(deposit) - Burn:
to = 0x0(withdrawal claim) - Lock:
to = vault address(withdrawal request — shares moved to vault)
Approval (ERC20)
event Approval(address indexed owner, address indexed spender, uint256 value);
Paused / Unpaused
event Paused(address account);
event Unpaused(address account);
Listening for Events (viem)
Watch Real-Time Events
import { createPublicClient, http, parseAbiItem } from "viem";
import { mainnet } from "viem/chains";
import vaultAbi from "./abi/EmeraldVault.json";
const publicClient = createPublicClient({
chain: mainnet,
transport: http("https://eth.llamarpc.com"),
});
// Watch for deposits
const unwatch = publicClient.watchContractEvent({
address: VAULT_ADDRESS,
abi: vaultAbi,
eventName: "Deposit",
onLogs: (logs) => {
for (const log of logs) {
console.log("New deposit:", {
sender: log.args.sender,
assets: log.args.assets,
shares: log.args.shares,
});
}
},
});
// To stop watching:
// unwatch();
Fetch Historical Events
const depositLogs = await publicClient.getContractEvents({
address: VAULT_ADDRESS,
abi: vaultAbi,
eventName: "Deposit",
fromBlock: 19_000_000n,
toBlock: "latest",
});
for (const log of depositLogs) {
console.log({
block: log.blockNumber,
txHash: log.transactionHash,
sender: log.args.sender,
assets: log.args.assets,
shares: log.args.shares,
});
}
Filter by User
// Get all withdrawal requests for a specific user
const withdrawalLogs = await publicClient.getContractEvents({
address: VAULT_ADDRESS,
abi: vaultAbi,
eventName: "WithdrawalRequested",
args: { user: "0x1234...abcd" }, // indexed parameter filter
fromBlock: 19_000_000n,
});
Event Topics (for raw filtering)
If you're building a custom indexer with raw log topics:
| Event | Topic 0 (keccak256) |
|---|---|
Deposit(address,address,uint256,uint256) | 0xdcbc1c05240f31ff3ad067ef1ee35ce4997762752e3a095284754544f4c709d7 |
WithdrawalRequested(address,uint256,uint256,uint256) | Use keccak256 of the full signature |
NAVUpdated(uint256,uint256,uint256) | Use keccak256 of the full signature |
Use viem's toEventHash() or ethers' id() to compute topic hashes at runtime.