Finance

This directory includes primitives for on-chain confidential financial systems:

Contracts

VestingWalletConfidential

import "@openzeppelin/confidential-contracts/finance/VestingWalletConfidential.sol";

A vesting wallet is an ownable contract that can receive ConfidentialFungibleTokens, and release these assets to the wallet owner, also referred to as "beneficiary", according to a vesting schedule.

Any assets transferred to this contract will follow the vesting schedule as if they were locked from the beginning. Consequently, if the vesting has already started, any amount of tokens sent to this contract will (at least partly) be immediately releasable.

By setting the duration to 0, one can configure this contract to behave like an asset timelock that holds tokens for a beneficiary until a specified time.

Since the wallet is Ownable, and ownership can be transferred, it is possible to sell unvested tokens.
When using this contract with any token whose balance is adjusted automatically (i.e. a rebase token), make sure to account the supply/balance adjustment in the vesting schedule to ensure the vested amount is as intended.
Functions
  • __VestingWalletConfidential_init(beneficiary, startTimestamp, durationSeconds)

  • start()

  • duration()

  • end()

  • released(token)

  • releasable(token)

  • release(token)

  • vestedAmount(token, timestamp)

  • _vestingSchedule(totalAllocation, timestamp)

ReentrancyGuardTransient
  • _reentrancyGuardEntered()

OwnableUpgradeable
  • __Ownable_init(initialOwner)

  • __Ownable_init_unchained(initialOwner)

  • owner()

  • _checkOwner()

  • renounceOwnership()

  • transferOwnership(newOwner)

  • _transferOwnership(newOwner)

ContextUpgradeable
  • __Context_init()

  • __Context_init_unchained()

  • _msgSender()

  • _msgData()

  • _contextSuffixLength()

Initializable
  • _checkInitializing()

  • _disableInitializers()

  • _getInitializedVersion()

  • _isInitializing()

  • _initializableStorageSlot()

Events
  • VestingWalletConfidentialTokenReleased(token, amount)

OwnableUpgradeable
  • OwnershipTransferred(previousOwner, newOwner)

Initializable
  • Initialized(version)

Errors
  • VestingWalletConfidentialInvalidDuration()

ReentrancyGuardTransient
  • ReentrancyGuardReentrantCall()

OwnableUpgradeable
  • OwnableUnauthorizedAccount(account)

  • OwnableInvalidOwner(owner)

Initializable
  • InvalidInitialization()

  • NotInitializing()

__VestingWalletConfidential_init(address beneficiary, uint48 startTimestamp, uint48 durationSeconds) internal

Initializes the vesting wallet for a given beneficiary with a start time of startTimestamp and an end time of startTimestamp + durationSeconds.

start() → uint64 public

Timestamp at which the vesting starts.

duration() → uint64 public

Duration of the vesting in seconds.

end() → uint64 public

Timestamp at which the vesting ends.

released(address token) → euint64 public

Amount of token already released

releasable(address token) → euint64 public

Getter for the amount of releasable token tokens. token should be the address of an IConfidentialFungibleToken contract.

release(address token) public

Release the tokens that have already vested.

vestedAmount(address token, uint64 timestamp) → euint128 public

Calculates the amount of tokens that has already vested. Default implementation is a linear vesting curve.

_vestingSchedule(euint128 totalAllocation, uint64 timestamp) → euint128 internal

This returns the amount vested, as a function of time, for an asset given its total historical allocation.

VestingWalletConfidentialTokenReleased(address indexed token, euint64 amount) event

VestingWalletConfidentialInvalidDuration() error

VestingWalletCliffConfidential

import "@openzeppelin/confidential-contracts/finance/VestingWalletCliffConfidential.sol";

An extension of VestingWalletConfidential that adds a cliff to the vesting schedule. The cliff is cliffSeconds long and starts at the vesting start timestamp (see VestingWalletConfidential).

Functions
  • __VestingWalletCliffConfidential_init(cliffSeconds)

  • cliff()

  • _vestingSchedule(totalAllocation, timestamp)

VestingWalletConfidential
  • __VestingWalletConfidential_init(beneficiary, startTimestamp, durationSeconds)

  • start()

  • duration()

  • end()

  • released(token)

  • releasable(token)

  • release(token)

  • vestedAmount(token, timestamp)

ReentrancyGuardTransient
  • _reentrancyGuardEntered()

OwnableUpgradeable
  • __Ownable_init(initialOwner)

  • __Ownable_init_unchained(initialOwner)

  • owner()

  • _checkOwner()

  • renounceOwnership()

  • transferOwnership(newOwner)

  • _transferOwnership(newOwner)

ContextUpgradeable
  • __Context_init()

  • __Context_init_unchained()

  • _msgSender()

  • _msgData()

  • _contextSuffixLength()

Initializable
  • _checkInitializing()

  • _disableInitializers()

  • _getInitializedVersion()

  • _isInitializing()

  • _initializableStorageSlot()

Events
VestingWalletConfidential
  • VestingWalletConfidentialTokenReleased(token, amount)

OwnableUpgradeable
  • OwnershipTransferred(previousOwner, newOwner)

Initializable
  • Initialized(version)

Errors
  • InvalidCliffDuration(cliffSeconds, durationSeconds)

VestingWalletConfidential
  • VestingWalletConfidentialInvalidDuration()

ReentrancyGuardTransient
  • ReentrancyGuardReentrantCall()

OwnableUpgradeable
  • OwnableUnauthorizedAccount(account)

  • OwnableInvalidOwner(owner)

Initializable
  • InvalidInitialization()

  • NotInitializing()

__VestingWalletCliffConfidential_init(uint48 cliffSeconds) internal

Set the duration of the cliff, in seconds. The cliff starts at the vesting start timestamp (see VestingWalletConfidential.start) and ends cliffSeconds later.

cliff() → uint64 public

The timestamp at which the cliff ends.

_vestingSchedule(euint128 totalAllocation, uint64 timestamp) → euint128 internal

This function returns the amount vested, as a function of time, for an asset given its total historical allocation. Returns 0 if the cliff timestamp is not met.

The cliff not only makes the schedule return 0, but it also ignores every possible side effect from calling the inherited implementation (i.e. super._vestingSchedule). Carefully consider this caveat if the overridden implementation of this function has any (e.g. writing to memory or reverting).

InvalidCliffDuration(uint64 cliffSeconds, uint64 durationSeconds) error

The specified cliff duration is larger than the vesting duration.

VestingWalletExecutorConfidential

import "@openzeppelin/confidential-contracts/finance/VestingWalletExecutorConfidential.sol";

Extension of VestingWalletConfidential that adds an executor role able to perform arbitrary calls on behalf of the vesting wallet (e.g. to vote, stake, or perform other management operations).

Functions
  • __VestingWalletExecutorConfidential_init(executor_)

  • executor()

  • call(target, value, data)

  • _call(target, value, data)

VestingWalletConfidential
  • __VestingWalletConfidential_init(beneficiary, startTimestamp, durationSeconds)

  • start()

  • duration()

  • end()

  • released(token)

  • releasable(token)

  • release(token)

  • vestedAmount(token, timestamp)

  • _vestingSchedule(totalAllocation, timestamp)

ReentrancyGuardTransient
  • _reentrancyGuardEntered()

OwnableUpgradeable
  • __Ownable_init(initialOwner)

  • __Ownable_init_unchained(initialOwner)

  • owner()

  • _checkOwner()

  • renounceOwnership()

  • transferOwnership(newOwner)

  • _transferOwnership(newOwner)

ContextUpgradeable
  • __Context_init()

  • __Context_init_unchained()

  • _msgSender()

  • _msgData()

  • _contextSuffixLength()

Initializable
  • _checkInitializing()

  • _disableInitializers()

  • _getInitializedVersion()

  • _isInitializing()

  • _initializableStorageSlot()

Events
  • VestingWalletExecutorConfidentialCallExecuted(target, value, data)

VestingWalletConfidential
  • VestingWalletConfidentialTokenReleased(token, amount)

OwnableUpgradeable
  • OwnershipTransferred(previousOwner, newOwner)

Initializable
  • Initialized(version)

Errors
  • VestingWalletExecutorConfidentialOnlyExecutor()

VestingWalletConfidential
  • VestingWalletConfidentialInvalidDuration()

ReentrancyGuardTransient
  • ReentrancyGuardReentrantCall()

OwnableUpgradeable
  • OwnableUnauthorizedAccount(account)

  • OwnableInvalidOwner(owner)

Initializable
  • InvalidInitialization()

  • NotInitializing()

__VestingWalletExecutorConfidential_init(address executor_) internal

executor() → address public

Trusted address that is able to execute arbitrary calls from the vesting wallet via call.

call(address target, uint256 value, bytes data) public

Execute an arbitrary call from the vesting wallet. Only callable by the executor.

_call(address target, uint256 value, bytes data) internal

Internal function for executing an arbitrary call from the vesting wallet.

VestingWalletExecutorConfidentialCallExecuted(address indexed target, uint256 value, bytes data) event

VestingWalletExecutorConfidentialOnlyExecutor() error

Thrown when a non-executor attempts to call call.