CrystalVaultFactory

Create and interact with individual vaults built on top of the Crystal protocol.

Functions

weth

function weth() external view returns (address)

Returns protocol configuration data or system constants without modifying on-chain state.

Return Values

Name
Type
Description

weth

address

Contract or wallet address


eth

function eth() external view returns (address)

Returns protocol configuration data or system constants without modifying on-chain state.

Return Values

Name
Type
Description

eth

address

Contract or wallet address


gov

function gov() external view returns (address)

Returns the governance/controller address for this factory

Return Values

Name
Type
Description

address

Contract or wallet address


crystal

Returns the address of the main Crystal contract this factory is paired with.

Return Values

Name
Type
Description

address

Contract or wallet address


allVaults

Returns the vault address at a given index in the factory’s list.

Parameters

Name
Type
Description

uint256

Numeric value

Return Values

Name
Type
Description

address

Contract or wallet address


allVaultsLength

Returns the amount of vaults the facotry is tracking

Return Values

Name
Type
Description

uint256

Unsigned integer value


getVault

Returns a full snapshot of a vault’s configuration and status: assets, owner, share counts, lockup, the “decrease on withdraw” flag, locked/closed flags, and the vault’s metadata.

Parameters

Name
Type
Description

vault

address

Vault contract address

Return Values

Name
Type
Description

quoteAsset

address

Quote token address

baseAsset

address

Base token address

owner

address

Vault owner address

totalShares

uint256

Total shares in vault

maxShares

uint256

Maximum allowed shares

lockup

uint40

Lockup period in seconds

decreaseOnWithdraw

bool

Whether to decrease position on withdrawal

locked

bool

Whether vault is locked

closed

bool

Whether vault is closed

metadata

ICrystalVault.VaultMetaData

Vault metadata


minSize

Returns the minimum valid trade size for a given token.

Parameters

Name
Type
Description

token

address

Token contract address

Return Values

Name
Type
Description

uint256

Unsigned integer value


defaultQuoteMin

Returns the default minimum amount for the quote asset.

Return Values

Name
Type
Description

uint256

Unsigned integer value


defaultBaseMin

Returns the default minimum amount for the base asset

Return Values

Name
Type
Description

uint256

Unsigned integer value


maxOrderCap

Returns a factory-level cap for a single order/operation, expressed as a uint16 (exact interpretation depends on the vault implementation).

Return Values

Name
Type
Description

uint16

Numeric result


maxLockup

Returns the maximum lockup duration the factory allows for any vault.

Return Values

Name
Type
Description

uint40

Numeric result


previewDeposit

Estimates how many shares would be minted and how much of each asset would actually be used if you deposited with those desired amounts, without changing state.

Parameters

Name
Type
Description

vault

address

Vault contract address

amountQuoteDesired

uint256

Desired quote token amount

amountBaseDesired

uint256

Desired base token amount

Return Values

Name
Type
Description

shares

uint256

Number of vault shares

amountQuote

uint256

Quote token amount

amountBase

uint256

Base token amount


previewWithdrawal

Estimates how many quote/base tokens you would receive for redeeming that number of shares, without changing state.

Parameters

Name
Type
Description

vault

address

Vault contract address

shares

uint256

Number of vault shares

Return Values

Name
Type
Description

amountQuote

uint256

Quote token amount

amountBase

uint256

Base token amount


balanceOf

Returns a user’s share balance in the vault, plus the user’s corresponding underlying quote/base amounts attributable to those shares.

Parameters

Name
Type
Description

vault

address

Vault contract address

user

address

User wallet address

Return Values

Name
Type
Description

shares

uint256

Number of vault shares

amountQuote

uint256

Quote token amount

amountBase

uint256

Base token amount


Events

VaultDeployed

Emitted when a new vault contract is deployed and initialized with configuration parameters.

Parameters

Name
Type
Description

vault

indexed address

Vault address

quoteAsset

address

Quote token address

baseAsset

address

Base token address

owner

address

Vault owner address

maxShares

uint256

Maximum allowed shares

lockup

uint256

Lockup period in seconds

decreaseOnWithdraw

bool

Whether to decrease position on withdrawal

metadata

ICrystalVault.VaultMetaData

Vault metadata


Deposit

Emitted when a user deposited into a vault; shows who, how many shares were minted, and the quote/base amounts contributed.

Parameters

Name
Type
Description

vault

indexed address

Vault address

sender

indexed address

Address initiating the action

shares

uint256

Number of vault shares

quoteAmount

uint256

Numeric value

baseAmount

uint256

Numeric value


Withdraw

Emitted when a user redeemed shares; shows who, how many shares were burned, and the quote/base amounts returned.

Parameters

Name
Type
Description

vault

indexed address

Vault address

sender

indexed address

Address initiating the action

shares

uint256

Number of vault shares

quoteAmount

uint256

Numeric value

baseAmount

uint256

Numeric value


MaxSharesChanged

Vault’s maximum share limit was updated.

Parameters

Name
Type
Description

vault

indexed address

Vault address

maxShares

uint256

Maximum allowed shares


LockupChanged

The vault’s lockup duration setting was updated.

Parameters

Name
Type
Description

vault

indexed address

Vault address

lockup

uint256

Lockup period in seconds


DecreaseOnWithdrawChanged

Emitted when vault toggled or updated its “decrease on withdraw” setting.

Parameters

Name
Type
Description

vault

indexed address

Vault address

newDecrease

bool

New decrease on withdraw setting


Locked

Emitted when a vault’s lock state changes: locked.

Parameters

Name
Type
Description

vault

indexed address

Vault address


Unlocked

Emitted when a vault’s lock state changes: unlocked.

Parameters

Name
Type
Description

vault

indexed address

Vault address


Closed

Emitted when a vault is permanently closed to all actions.

Parameters

Name
Type
Description

vault

indexed address

Vault address


Structs

Vault

Describes one vault’s setup and status: which two assets it holds, who owns it, total and maximum shares, any lockup period, whether a “decrease on withdraw” rule is enabled, current lock/close flags, and human-readable metadata supplied by the vault (VaultMetaData).

Parameters

Name
Type
Description

quoteAsset

address

Quote token address

baseAsset

address

Base token address

owner

address

Vault owner address

totalShares

uint256

Total shares in vault

maxShares

uint256

Maximum allowed shares

lockup

uint40

Lockup period in seconds

decreaseOnWithdraw

bool

Whether to decrease position on withdrawal

locked

bool

Whether vault is locked

closed

bool

Whether vault is closed

metadata

ICrystalVault.VaultMetaData

Vault metadata

Last updated