StakedToken
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
| Name | Type | Description |
|---|---|---|
_asset | IERC20 | The underlying plDXY token to stake (plDXY-BEAR or plDXY-BULL). |
_name | string | Vault share name (e.g., “Staked plDXY-BEAR”). |
_symbol | string | Vault 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
| Name | Type | Description |
|---|---|---|
amount | uint256 | The 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
| Name | Type | Description |
|---|---|---|
assets | uint256 | Amount of underlying tokens to deposit |
receiver | address | Address to receive the vault shares |
deadline | uint256 | Permit signature expiration timestamp |
v | uint8 | Signature recovery byte |
r | bytes32 | Signature r component |
s | bytes32 | Signature s component |
Returns
| Name | Type | Description |
|---|---|---|
shares | uint256 | Amount 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();