Treasury

Git Source

Inherits:ITREASURY, Initializable, UUPSUpgradeable, PausableUpgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable

Treasury contract with 3-year linear vesting and external multisig support

Implements a secure and upgradeable treasury with vesting for ETH and ERC20 tokens

Notes:

  • security-contact: security@nebula-labs.xyz

  • copyright: Copyright (c) 2025 Nebula Holding Inc. All rights reserved.

  • oz-upgrades:

State Variables

MANAGER_ROLE

Role identifier for accounts that can release funds

bytes32 public constant MANAGER_ROLE = keccak256("MANAGER_ROLE");

PAUSER_ROLE

Role identifier for accounts that can pause/unpause the contract

bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");

UPGRADER_ROLE

Role identifier for accounts that can upgrade the contract

UPGRADE_TIMELOCK_DURATION

Upgrade timelock duration in seconds (3 days)

_version

Current version of the contract implementation Incremented during upgrades

_start

Start timestamp of the vesting schedule

_duration

Duration of the vesting period in seconds

_released

Total amount of ETH already released

_timelockAddress

Timelock controller address

_erc20Released

Mapping of token address to amount released for each token

pendingUpgrade

Pending upgrade information

__gap

Reserved storage space for future upgrades This allows adding new state variables in future versions while maintaining the storage layout (30 - 7 = 23)

Functions

nonZeroAddress

Modifier to check for non-zero address

Parameters

Name
Type
Description

addr

address

The address to check

nonZeroAmount

Modifier to check for non-zero amount

Parameters

Name
Type
Description

amount

uint256

The amount to check

constructor

Prevents initialization of the implementation contract

Note: oz-upgrades-unsafe-allow: constructor

receive

Allows the contract to receive ETH

Emits a {Received} event

initialize

Initializes the treasury contract

Sets up the initial state of the contract

Parameters

Name
Type
Description

timelock

address

The address that will have the DEFAULT_ADMIN_ROLE and MANAGER_ROLE

multisig

address

The address of the Gnosis Safe multisig that will be granted the UPGRADER_ROLE

startOffset

uint256

The number of seconds the start time is before the current block timestamp

vestingDuration

uint256

The duration of vesting in seconds (must be at least 730 days)

pause

Pauses all token transfers and releases

Can only be called by accounts with the PAUSER_ROLE

unpause

Unpauses token transfers and releases

Can only be called by accounts with the PAUSER_ROLE

release

Releases a specific amount of vested ETH

Can only be called by accounts with the MANAGER_ROLE

Reverts if the requested amount exceeds vested amount

Parameters

Name
Type
Description

to

address

The address that will receive the ETH

amount

uint256

The amount of ETH to release

release

Releases a specific amount of vested tokens

Can only be called by accounts with the MANAGER_ROLE

Reverts if the requested amount exceeds vested amount

Parameters

Name
Type
Description

token

address

The ERC20 token to release

to

address

The address that will receive the tokens

amount

uint256

The amount of tokens to release

updateVestingSchedule

Updates the vesting schedule parameters

Can only be called by accounts with the DEFAULT_ADMIN_ROLE

Parameters

Name
Type
Description

newStart

uint256

The new start timestamp

newDuration

uint256

The new duration in seconds

emergencyWithdrawToken

Only callable by addresses with MANAGER_ROLE

Emergency function to withdraw all tokens to the timelock

Notes:

  • throws: ZeroAddress if token address is zero

  • throws: ZeroBalanceError if contract has no token balance

Parameters

Name
Type
Description

token

address

The ERC20 token to withdraw

emergencyWithdrawEther

Only callable by addresses with MANAGER_ROLE

Emergency function to withdraw all ETH to the timelock

Note: throws: ZeroBalanceError if contract has no ETH balance

scheduleUpgrade

Schedules an upgrade to a new implementation

Parameters

Name
Type
Description

newImplementation

address

Address of the new implementation

cancelUpgrade

Cancels a previously scheduled upgrade

Only callable by addresses with UPGRADER_ROLE

upgradeTimelockRemaining

Returns the remaining time before a scheduled upgrade can be executed

Returns

Name
Type
Description

<none>

uint256

timeRemaining The time remaining in seconds, or 0 if no upgrade is scheduled or timelock has passed

timelockAddress

Get the timelock controller address

Returns

Name
Type
Description

<none>

address

The timelock controller address

releasable

Returns the amount of ETH that can be released now

Returns

Name
Type
Description

<none>

uint256

Amount of releasable ETH

releasable

Returns the amount of a specific token that can be released now

Parameters

Name
Type
Description

token

address

The ERC20 token to check

Returns

Name
Type
Description

<none>

uint256

Amount of releasable tokens

vestedAmount

Calculates the amount of ETH vested at a specific timestamp

Parameters

Name
Type
Description

timestamp

uint256

The timestamp to check

Returns

Name
Type
Description

<none>

uint256

The vested amount of ETH

vestedAmount

Calculates the amount of tokens vested at a specific timestamp

Parameters

Name
Type
Description

token

address

The ERC20 token to check

timestamp

uint256

The timestamp to check

Returns

Name
Type
Description

<none>

uint256

The vested amount of tokens

version

Returns the current contract version

Returns

Name
Type
Description

<none>

uint32

Current version number

start

Returns the start timestamp of the vesting period

Returns

Name
Type
Description

<none>

uint256

Start timestamp

duration

Returns the duration of the vesting period

Returns

Name
Type
Description

<none>

uint256

Duration in seconds

end

Returns the end timestamp of the vesting period

Returns

Name
Type
Description

<none>

uint256

End timestamp (start + duration)

released

Returns the amount of ETH already released

Returns

Name
Type
Description

<none>

uint256

Amount of ETH released so far

released

Returns the amount of a specific token already released

Parameters

Name
Type
Description

token

address

The ERC20 token to check

Returns

Name
Type
Description

<none>

uint256

Amount of tokens released so far

_authorizeUpgrade

Authorizes and processes contract upgrades with timelock enforcement

Internal override for UUPS upgrade authorization

Parameters

Name
Type
Description

newImplementation

address

Address of the new implementation contract

_vestingSchedule

Internal function to calculate vested amounts for a given allocation and timestamp

Uses linear vesting between start and end time

Parameters

Name
Type
Description

totalAllocation

uint256

The total amount to vest

timestamp

uint256

The timestamp to check

Returns

Name
Type
Description

<none>

uint256

The amount vested at the specified timestamp

Last updated