stTBY

Overview

StTBY is a contract that represents staked USD tokens. The contract allows for deposits of TBY tokens to mint stTBY, the redemption of stTBY and wstTBY to get the underlying tokens and withdrawal of redeemed underlying tokens. It's built on top of OpenZeppelin's standards for security.

Structs

Redemption

Represents the redemption state for an account.

  • pending (uint256): Amount of redemption that is pending.

  • withdrawn (uint256): Amount that has been withdrawn from the redemption.

  • redemptionQueueTarget (uint256): Target in the vault's redemption queue.

Storage

  • wstTBY (IWstTBY): Token address for wstTBY.

  • underlyingToken (IERC20, immutable): Token address for the underlying token.

  • _whitelisted (mapping): Mapping to store addresses that are whitelisted.

Events

  • TBYWhitelisted: Emitted when a new TBY address is whitelisted.

  • Redeemed: Emitted when LP tokens are redeemed.

  • Withdrawn: Emitted when redeemed underlying tokens are withdrawn.

Errors

The contract defines a set of custom errors:

  • InvalidAddress: Thrown when an invalid address is provided.

  • ParameterOutOfBounds: Thrown when a parameter is out of valid bounds.

  • InsufficientBalance: Thrown when a user's balance is insufficient.

  • RedemptionInProgress: Thrown when there's already a redemption in progress for the user.

  • InvalidAmount: Thrown when an invalid amount is provided.

  • TBYNotWhitelisted: Thrown when a TBY is not whitelisted.

  • AlreadyInitialized: Thrown if WstTBY is already initialized.

Key Functions

deposit(address _tby, uint256 _amount)

Allows users to deposit TBY tokens and get stTBY minted in return. Emits a Deposit event.

redeemStTBY(uint256 _stTBYAmount) & redeemWstTBY(uint256 _wstTBYAmount)

Allows users to redeem stTBY or wstTBY in exchange for underlying tokens. The tokens can be withdrawn with the withdraw() function, once the redemption is processed.

withdraw()

Allows users to withdraw redeemed underlying tokens.

redemptions(address account)

Fetches the redemption state for an account.

redemptionAvailable(address account, uint256 processedRedemptionQueue)

Returns the amount of redemption available for withdrawal for an account.

Owner Restricted Functions

Functions that can only be accessed by the contract owner:

  • setTotalUsd(uint256 _amount): Update the _totalUsd value.

  • whitelistTBY(address _tby, bool _whitelist): Whitelist a TBY address.

  • redeemUnderlying(address _tby, uint256 _amount): Redeem underlying tokens from a TBY.

  • depositUnderlying(address _tby): Deposit remaining underlying tokens to a new TBY.

  • pause(): Pause the contract.

  • unpause(): Unpause the contract.

Modifiers

The contract uses several modifiers to enhance the functionality and security:

  • onlyOwner: Ensures that only the owner can call the function.

  • whenNotPaused: Ensures that the function can only be called when the contract is not paused.

  • nonReentrant: Ensures that the function is not recursively called by malicious contracts.

Last updated