Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

StakedToken

Git Source

Inherits: ERC4626

Title: StakedToken

ERC4626 vault for staking plDXY-BEAR or plDXY-BULL tokens.

Used as Morpho collateral. Exchange rate increases via yield donations. Implements 1000x virtual share offset to prevent inflation attacks. Implements streaming rewards (1-hour linear vest) to prevent reward sniping.

Note: security-contact: contact@plether.com

Constants

STREAM_DURATION

Duration over which donated rewards are streamed.

uint256 public constant STREAM_DURATION = 1 hours

State Variables

_trackedBalance

uint256 private _trackedBalance

rewardRate

Current reward streaming rate (tokens per second, scaled by 1e18).

uint256 public rewardRate

streamEndTime

Timestamp when current reward stream ends.

uint256 public streamEndTime

Functions

constructor

Creates a new staking vault for a synthetic token.

constructor(
    IERC20 _asset,
    string memory _name,
    string memory _symbol
) ERC4626(_asset) ERC20(_name, _symbol);

Parameters

NameTypeDescription
_assetIERC20The underlying plDXY token to stake (plDXY-BEAR or plDXY-BULL).
_namestringVault share name (e.g., “Staked plDXY-BEAR”).
_symbolstringVault share symbol (e.g., “splDXY-BEAR”).

totalAssets

Returns total assets including only vested streamed rewards.

Overrides ERC4626 to exclude unvested rewards from share price calculation.

function totalAssets() public view override returns (uint256);

donateYield

Donates yield that streams to stakers over STREAM_DURATION.

Rewards vest linearly. New donations extend the stream proportionally to the donation size, preventing griefing via zero-amount timer resets.

function donateYield(
    uint256 amount
) external;

Parameters

NameTypeDescription
amountuint256The amount of underlying tokens to donate.

depositWithPermit

Deposit assets with a permit signature (gasless approval).

Combines EIP-2612 permit with ERC-4626 deposit in a single transaction.

function depositWithPermit(
    uint256 assets,
    address receiver,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
) external returns (uint256 shares);

Parameters

NameTypeDescription
assetsuint256Amount of underlying tokens to deposit
receiveraddressAddress to receive the vault shares
deadlineuint256Permit signature expiration timestamp
vuint8Signature recovery byte
rbytes32Signature r component
sbytes32Signature s component

Returns

NameTypeDescription
sharesuint256Amount of vault shares minted

_deposit

function _deposit(
    address caller,
    address receiver,
    uint256 assets,
    uint256 shares
) internal override;

_withdraw

function _withdraw(
    address caller,
    address receiver,
    address owner,
    uint256 assets,
    uint256 shares
) internal override;

_unvestedRewards

Calculates unvested rewards from the current stream.

function _unvestedRewards() internal view returns (uint256);

_decimalsOffset

Virtual share offset (10^3 = 1000x) to prevent inflation attacks.

function _decimalsOffset() internal pure override returns (uint8);

Events

YieldDonated

Emitted when yield is donated and streaming begins/extends.

event YieldDonated(address indexed donor, uint256 amount, uint256 newStreamEndTime);

Errors

StakedToken__PermitFailed

error StakedToken__PermitFailed();