Spectra Developer Docs
  • Developers Documentation
  • Getting Started
  • Guides
    • Tokenizing Yield
    • Providing Liquidity
    • Deploy PT and Curve Pool
    • Routing
    • IBT Additional Rewards
    • Locking APW for veAPW
    • Voting and Earning Rewards
  • Technical Reference
    • Deployed Contracts
    • Contract Functions
      • Principal Token
      • Yield Token
      • Registry
      • RateOracle
      • Factory
      • Access Manager
      • RouterUtil
      • Router
      • GovernanceRegistry
      • Voter
      • VotingReward
        • BribeVotingReward
        • FeesVotingReward
      • FeeDistributor
      • Spectra4626Wrapper
    • Yield Calculations
    • Spectra's Automated Market Makers
      • Rate Adjusted StableSwap pools
  • Glossary
  • INTEGRATION REFERENCE
    • Spectra Oracles
      • TWAP Oracles
      • Deterministic Oracles
        • Linear APR model
        • Linear Discount Model
        • Zero Coupon Bond Model
        • Comparison
      • Oracle Deployment
        • Deterministic Oracles Deployment
        • TWAP Oracles Deployment
Powered by GitBook
On this page
  • Methods
  • deposit
  • deposit
  • deposit
  • depositIBT
  • depositIBT
  • depositIBT
  • redeem
  • redeem
  • redeemForIBT
  • redeemForIBT
  • withdraw
  • withdraw
  • withdrawIBT
  • withdrawIBT
  • claimYield
  • claimYieldInIBT
  • updateYield
  • flashLoan
  • StoreRatesAtExpiry
  • View Methods
  • previewDeposit
  • maxDeposit
  • previewDepositIBT
  • previewWithdraw
  • previewWithdrawIBT
  • maxWithdraw
  • maxWithdrawIBT
  • previewRedeem
  • previewRedeemForIBT
  • maxRedeem
  • convertToPrincipal
  • convertToUnderlying
  • underlying
  • totalAssets
  • decimals
  • maturity
  • getDuration
  • getIBT
  • getYT
  • getIBTRate
  • getPTRate
  • getIBTUnit
  • getAssetUnit
  • getIBTRateAtExpiry
  • getPTRateAtExpiry
  • getCurrentYieldOfUserInIBT
  • Internal Methods
  • _computeYield
  1. Technical Reference
  2. Contract Functions

Principal Token

PreviousContract FunctionsNextYield Token

Last updated 1 year ago

The Principal Token is the main contract of Spectra. It is EIP , and compliant.

Users deposit the (or underlying token of the IBT) and receive the Principal Token (PT) and the (YT) in return. For example, user deposits aDAI (or DAI) and receives the PT and YT of the aDAI position with a certain expiry.

The user can also and after and before expiry. For more information, see the guide.

Code for PrincipalToken.sol can be found on .

Methods

deposit

function deposit(
    uint256 assets,
    address receiver
) public returns (uint256 shares)

Deposits the amount of the underlying assets (e.g. DAI or USDC etc) and mints an amount of shares (i.e. ) and for the receiver.

msg.sender must approve the relevant allowance of the underlying asset before calling this method.

deposit must be called before the of the Principal Token.

Input Parameter
Type
Description

assets

uint256

The amount of the underlying assets to deposit.

receiver

address

Return Parameter
Type
Description

shares

uint256

deposit

function deposit(
        uint256 assets,
        address ptReceiver,
        address ytReceiver
) external returns (uint256 shares);

Deposits amount of assets in the PT vault specifying the PT receiver (ptReceiver) and the YT receiver (ytReceiver).

msg.sender must approve the relevant allowance of the underlying asset before calling this method.

Input Parameter
Type
Description

assets

uint256

The amount of the underlying assets to deposit.

ptReceiver

address

ytReceiver

address

Return Parameter
Type
Description

shares

uint256

deposit

function deposit(
    uint256 assets,
    address ptReceiver,
    address ytReceiver,
    uint256 minShares
) external returns (uint256 shares);

Deposits amount of assets with a lower bound on shares received (minShares).

msg.sender must approve the relevant allowance of the underlying asset before calling this method.

Input Parameter
Type
Description

assets

uint256

The amount of the underlying assets to deposit.

ptReceiver

address

ytReceiver

address

minShares

uint256

The minimum amount of shares the caller expect to receive from the posit

Return Parameter
Type
Description

shares

uint256

depositIBT

function depositIBT(
    uint256 ibts,
    address receiver
) public returns (uint256 shares)

msg.sender must approve the relevant allowance of the IBT before calling this method.

Input Parameter
Type
Description

ibts

uint256

The amount of the PrincipalToken's IBT assets to deposit.

receiver

address

Return Parameter
Type
Description

shares

uint256

depositIBT

function depositIBT(
        uint256 ibts,
        address ptReceiver,
        address ytReceiver
) external returns (uint256 shares);

msg.sender must approve the relevant allowance of the IBT before calling this method.

Input Parameter
Type
Description

ibts

uint256

The amount of the PrincipalToken's IBT assets to deposit.

ptReceiver

address

ytReceiver

address

Return Parameter
Type
Description

shares

uint256

depositIBT

function depositIBT(
        uint256 ibts,
        address ptReceiver,
        address ytReceiver,
        uint256 minShares
) external returns (uint256 shares);

msg.sender must approve the relevant allowance of the IBT before calling this method.

Input Parameter
Type
Description

ibts

uint256

The amount of the PrincipalToken's IBT assets to deposit.

ptReceiver

address

ytReceiver

address

minShares

uint256

The minimum amount of shares the caller expect to receive from the posit

Return Parameter
Type
Description

shares

uint256

redeem

function redeem(
    uint256 shares,
    address receiver,
    address owner
) returns (uint256 assets)
Input Parameter
Type
Description

shares

uint256

receiver

address

owner

address

Return Parameter
Type
Description

assets

uint256

redeem

function redeem(
        uint256 shares,
        address receiver,
        address owner,
        uint256 minAssets
) external returns (uint256 assets);

I.e. converts PT to the underlying asset, using the number of PT to burn, after expiry.

Input Parameter
Type
Description

shares

uint256

receiver

address

owner

address

minAssets

uint256

The minimum asset amount that the caller expects the receiver to receive.

Return Parameter
Type
Description

assets

uint256

redeemForIBT

function redeemForIBT(
    uint256 shares,
    address receiver,
    address owner
) returns (uint256 ibts)
Input Parameter
Type
Description

shares

uint256

receiver

address

The address that will receive the redeemed tokens.

owner

address

Return Parameter
Type
Description

ibts

uint256

redeemForIBT

function redeemForIBT(
        uint256 shares,
        address receiver,
        address owner,
        uint256 minIbts
) external returns (uint256 ibts);
Input Parameter
Type
Description

shares

uint256

receiver

address

The address that will receive the redeemed tokens.

owner

address

minIbts

uint256

The minimum asset amount that the caller expects the receiver to receive.

Return Parameter
Type
Description

ibts

uint256

withdraw

function withdraw(
    uint256 assets,
    address receiver,
    address owner
) returns (uint256 shares)
Input Parameter
Type
Description

assets

uint256

receiver

address

owner

address

Return Parameter
Type
Description

shares

uint256

withdraw

function withdraw(
        uint256 assets,
        address receiver,
        address owner,
        uint256 maxShares
) external returns (uint256 shares)

I.e. converts PT and YT to the underlying asset, using the number of underlying assets to withdraw, before expiry.

Input Parameter
Type
Description

assets

uint256

receiver

address

owner

address

maxShares

uint256

The maximum amount of shares allowed to be burnt

Return Parameter
Type
Description

shares

uint256

withdrawIBT

function withdrawIBT(
    uint256 ibts,
    address receiver,
    address owner
) returns (uint256 shares)
Input Parameter
Type
Description

ibts

uint256

receiver

address

The address that will receive the withdrawn tokens.

owner

address

Return Parameter
Type
Description

shares

uint256

withdrawIBT

function withdrawIBT(
        uint256 ibts,
        address receiver,
        address owner,
        uint256 maxShares
) external returns (uint256 shares)
Input Parameter
Type
Description

ibts

uint256

receiver

address

The address that will receive the withdrawn tokens.

owner

address

maxShares

uint256

The maximum amount of shares allowed to be burnt

Return Parameter
Type
Description

shares

uint256

claimYield

function claimYield(address _receiver) public returns (uint256)

Claims the yield of msg.sender based on their current balance of YT. Send the yield as underlying tokens.

Input Parameter
Type
Description

_receiver

address

The address that will receive the yield.

Return Parameter
Type
Description

yieldInAsset

uint256

claimYieldInIBT

function claimYieldInIBT(address _receiver) public returns (uint256)
Input Parameter
Type
Description

_receiver

address

The address that will receive the yield.

Return Parameter
Type
Description

yieldInIBT

uint256

updateYield

function updateYield(address _user) external returns (uint256 updatedUserYieldInRay)

Updates _user yield with the latest yield in IBT generated since the previous update.

This method should not be used by users. This method is called implicitely before each action to deposit, redeem, withdraw and sending receiving YT tokens.

Input Parameter
Type
Description

_user

address

The address of the user to compute the yield

Return Parameter
Type
Description

updatedUserYieldInRay

uint256

flashLoan

function flashLoan(
        IERC3156FlashBorrower _receiver,
        address _token,
        uint256 _amount,
        bytes calldata _data
    ) external override returns (bool)

The flashLoan method is used to swap PT for YT tokens by borrowing the IBT of the PT contract to swap PT for YTs.

The transaction reverts if the trade is not profitable and the borrower is unable to repay the loan.

Input Parameter
Type
Description

_receiver

IERC3156FlashBorrower

The receiver of the tokens in the loan, and the receiver of the callback.

_token

address

The loan currency.

_amount

uint256

The amount of tokens lent.

_data

bytes calldata

Arbitrary data structure, intended to contain user-defined parameters.

Return Parameter
Type
Description

bool

If successful, flashLoan return true.

StoreRatesAtExpiry

Store the rates at the time of expiry.

function storeRatesAtExpiry() external

View Methods

previewDeposit

function previewDeposit(uint256 assets) public view returns (uint256)

maxDeposit

function maxDeposit(address) public view returns (uint256)

previewDepositIBT

function previewDepositIBT(uint256 ibts) public view returns (uint256)

previewWithdraw

function previewWithdraw(uint256 assets) public view returns (uint256)

previewWithdrawIBT

function previewWithdrawInIBT(uint256 ibts) public view returns (uint256)

maxWithdraw

function maxWithdraw(address owner) public returns (uint256)

maxWithdrawIBT

function maxWithdraw(address owner) public returns (uint256)

previewRedeem

function previewRedeem(uint256 shares) public view returns (uint256)

previewRedeemForIBT

function previewRedeemForIBT(uint256 shares) public view returns (uint256)

maxRedeem

function maxRedeem(address owner) public view returns (uint256)

convertToPrincipal

function convertToPrincipal(uint256 underlyingAmount) public view returns (uint256 principalAmount)

Calculates the amount of principal tokens that are equivalent to the amount of underlyingAmount.

convertToUnderlying

function convertToUnderlying(uint256 principalAmount) public view returns (uint256)

underlying

function underlying() public view virtual override returns (address)

Returns the address of the underlying ERC20 or ERC777 asset.

E.g. if the IBT is aDAI, then the asset is DAI. If the IBT is cUSDC, then the asset is USDC.

totalAssets

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

decimals

function decimals() public view returns (uint8)

maturity

function maturity() public view returns (uint256)

getDuration

function getDuration() public view returns (uint256)

Returns the total duration of the principal token period in seconds.

getIBT

function getIBT() public view returns (address)

E.g. if the underlying asset is DAI, the IBT could be aDAI (for Aave deposited DAI) or cDAI (for Compound deposited DAI), etc.

getYT

function getYT() public view returns (address)

getIBTRate

function getIBTRate() public view returns (uint256)

Returns the ibtRate.

getPTRate

function getPTRate() public view returns (uint256)

Returns the ptRate.

getIBTUnit

function getIBTUnit() public view returns (uint256)

getAssetUnit

function getAssetUnit() public view returns (uint256)

getIBTRateAtExpiry

function getIBTRateAtExpiry() public view returns (uint256)

getPTRateAtExpiry

function getPTRateAtExpiry() public view returns (uint256)

getCurrentYieldOfUserInIBT

function getCurrentYieldOfUserInIBT(address _user) public view returns (uint256 _yieldOfUserInIBT)

Internal Methods

_computeYield

function _computeYield(
    address _user,
    uint256 _oldIBTRate,
    uint256 _ibtRate,
    uint256 _oldPTRate,
    uint256 _ptRate
) internal view returns (uint256)

See also

The address that will receive the minted and . Note: This can be different from msg.sender if depositing on behalf of another address.

The amount of shares (i.e. ) and that were minted for the receiver.

deposit must be called before the of the Principal Token.

See also

The address that will receive the minted Note: This can be different from msg.sender if depositing on behalf of another address.

The address that will receive the minted Note: This can be different from msg.sender if depositing on behalf of another address.

The amount of shares (i.e. ) and that were minted for the receiver.

deposit must be called before the of the Principal Token.

See also

The address that will receive the minted Note: This can be different from msg.sender if depositing on behalf of another address.

The address that will receive the minted Note: This can be different from msg.sender if depositing on behalf of another address.

The amount of shares (i.e. ) and that were minted for the receiver.

Deposits the ibts of the (e.g. aDAI or aUSDC etc) and mints an amount of shares (i.e. ) and for the receiver.

deposit must be called before the of the Principal Token.

See also

The address that will receive the minted and . Note: This can be different from msg.sender if depositing on behalf of another address.

The amount of shares (i.e. ) and that were minted for the receiver.

Deposits the ibts of the (e.g. aDAI or aUSDC etc) and mints an amount of shares (i.e. ) for the ptReceiver and for the ytReceiver.

deposit must be called before the of the Principal Token.

See also

The address that will receive the minted Note: This can be different from msg.sender if depositing on behalf of another address.

The address that will receive the minted Note: This can be different from msg.sender if depositing on behalf of another address.

The amount of shares (i.e. ) and that were minted for the receiver.

Deposits the ibts of the (e.g. aDAI or aUSDC etc) and mints an amount of shares (i.e. ) for the ptReceiver and for the ytReceiver.

deposit must be called before the of the Principal Token.

See also

The address that will receive the minted Note: This can be different from msg.sender if depositing on behalf of another address.

The address that will receive the minted Note: This can be different from msg.sender if depositing on behalf of another address.

The amount of shares (i.e. ) and that were minted for the receiver.

Redeems (by burning tokens) the amount of shares (i.e. ) from owner, redeeming an amount of assets of the underlying .

The first caller to Redeem after expiry will make an implicit call to to store the rates after expiry. This is done only once for all.

The amount of shares (i.e. ) that the user wants to redeem/burn.

The address that will receive the redeemed .

The address of the owner of the shares (i.e. ) that are to be redeemed. This must be the same as msg.sender.

The amount of underlying that are redeemed.

Conforms to standards.

Redeems (by burning tokens) the amount of shares (i.e. ) from owner, redeeming an amount of assets of the underlying , while also specifying the minimum asset (minAssets) amount that the caller expects the receiver to receive.

The first caller to Redeem after expiry will make an implicit call to to store the rates after expiry. This is done only once for all.

The amount of shares (i.e. ) that the user wants to redeem/burn.

The address that will receive the redeemed .

The address of the owner of the shares (i.e. ) that are to be redeemed. This must be the same as msg.sender.

The amount of underlying that are redeemed.

Redeems (by burning tokens) the amount of shares (i.e. ) from owner, redeeming an amount of ibts of the .

The first caller to Redeem after expiry will make an implicit call to to store the rates after expiry. This is done only once for all.

The amount of shares (i.e. ) that the user wants to redeem/burn.

The address of the owner of the shares (i.e. ) that are to be redeemed. This must be the same as msg.sender.

The amount of s that are redeemed.

Redeems (by burning tokens) the amount of shares (i.e. ) from owner, redeeming an amount of ibts of the , while also specifying the minimum asset (minIbts) amount that the caller expects the receiver to receive.

The first caller to Redeem after expiry will make an implicit call to to store the rates after expiry. This is done only once for all.

The amount of shares (i.e. ) that the user wants to redeem/burn.

The address of the owner of the shares (i.e. ) that are to be redeemed. This must be the same as msg.sender.

The amount of s that are redeemed.

Withdraws the amount of underlying assets of a position of owner, withdrawing those assets to receiver. This is done by burning shares (i.e. ) and remaining of owner.

The amount of that the user wants to withdraw.

The address that will receive the redeemed .

The address of the owner of the shares (i.e. ) that are to be withdrawn/burned. This must be the same as msg.sender.

The amount of the owner shares (i.e. ) that were burned from the withdrawal.

Conforms to standards.

Withdraws the amount of underlying assets of a position of owner, withdrawing those assets to receiver. This is done by burning shares (i.e. ) and remaining of owner, while specifying the maximum amount (maxShares) of shares to withdraw.

The amount of that the user wants to withdraw.

The address that will receive the redeemed .

The address of the owner of the shares (i.e. ) that are to be withdrawn/burned. This must be the same as msg.sender.

The amount of the owner shares (i.e. ) that were burned from the withdrawal.

Withdraws the amount of s of a position of owner, withdrawing those ibts to receiver. This is done by burning shares (i.e. ) and remaining of owner.

The amount of s that the user wants to withdraw.

The address of the owner of the shares (i.e. ) that are to be withdrawn/burned. This must be the same as msg.sender.

The amount of the owner shares (i.e. ) that were burned from the withdrawal.

Withdraws the amount of s of a position of owner, withdrawing those ibts to receiver. This is done by burning shares (i.e. ) and remaining of owner, while specifying the maximum amount (maxShares) of shares to withdraw.

The amount of s that the user wants to withdraw.

The address of the owner of the shares (i.e. ) that are to be withdrawn/burned. This must be the same as msg.sender.

The amount of the owner shares (i.e. ) that were burned from the withdrawal.

The amount of yield claimed in the underlying .

Claims the yield of msg.sender based on their current balance of YT. Send the yield as tokens.

The amount of yield claimed (in ).

The unclaimed yield (amount of tokens) of the _user in Ray decimals. The user can get this yield by calling .

Conforms to standards.

This can only be called after of the position.

Calculates the amount of shares (i.e. ) and that would be minted for amount of assets.Only available if position is not

This function returns the maximum amount of underlying assets that can be deposited in a single call by the receiver.

Calculates the amount of shares (i.e. ) and that would be minted for amount of ibts.Only available if position is not

Calculates the amount of shares (i.e. ) that would be burned for an amount of assets.

Conforms to standards.

Calculates the amount of shares (i.e. ) that would be burned for an amount of ibts.

Calculates the maximum amount of underlying that can by the owner.

Conforms to standards.

Calculates the maximum amount of s that can by the owner.

Calculates the amount of that would be for an amount of shares (i.e. ).

Conforms to standards.

Calculates the amount of IBTs that would be for an amount of shares (i.e. ).

Calculations the maximum amount of shares (i.e. ) that the owner can currently /burn.

Conforms to standards.

Conforms to standard.

Same as .

Conforms to standard.

Conforms to standard.

Returns the total balance of the underlying assets in the . Useful for TVL calculations.

Returns the decimals of the .

Returns the expiry/maturity of the position in unix timestamp, at or after which the can be redeemed for their underlying .

Conforms to standard.

Returns the address of the IBT ().

Returns the address of the YT ().

Returns the number used for one unit (10^decimals) of the .

Returns the number used for one unit (10^decimals) of the .

Returns the IBT rate at expiry. Only valid after .

Returns the PT rate at expiry. Only valid after .

Returns the yield of _user in tokens.

Computes the yield generated by a user given old and new rates. For more information, see the page.

ERC-5095
ERC-5095
EIP-3156
ERC-5095
ERC-5095
ERC-5095
ERC-5095
EIP-5095
ERC-5095
ERC-5095
ERC-5095
Yield Calculations
expiry
expiry
expiry
expiry
expiry
StoreRatesAtExpiry()
StoreRatesAtExpiry()
StoreRatesAtExpiry()
StoreRatesAtExpiry()
expiry
/maturity
deposit
assets
withdrawn
convertToAssets()
IBT
IBT
asset
maturity
maturity
YT
YT
YT
YT
asset()
asset()
asset()
getIBT()
getIBT()
getIBT()
assets
assets
assets
assets
assets
assets
assets
assets
asset
5095
2612
Tokenising Yield
GitHub
withdraw
redeem
expiry
asset
asset
depositing
expired/reached maturity.
depositing
expired/reached maturity.
withdrawing
withdrawing
withdrawn
assets
redeemed
redeemed
redeem
asset
claimYield()
IBT
Yield Token
Principal Tokens
Yield Tokens
Interest Bearing Token
Principal Tokens
Yield Tokens
Interest Bearing Token
Principal Tokens
Yield Tokens
Interest Bearing Token
Principal Tokens
Yield Tokens
Principal Tokens
Principal Tokens
Principal Tokens
IBT
Principal Tokens
IBT
Principal Tokens
Yield Tokens
Principal Tokens
Yield Tokens
IBT
Principal Tokens
Yield Tokens
IBT
Principal Tokens
Yield Tokens
IBT
Principal Tokens
Yield Tokens
Principal Tokens
Yield Tokens
Principal Tokens
Principal Tokens
IBT
Principal Tokens
Principal Tokens
Principal Tokens
Principal Token
Principal Tokens
Interest Bearing Token
Yield Token
IBT
PT
YT
Principal Tokens
Yield Tokens
PT
Principal Tokens
Yield Tokens
PT
Principal Tokens
Yield Tokens
PT
YT
Principal Tokens
Yield Tokens
PT
Principal Tokens
Yield Tokens
PT
Principal Tokens
Yield Tokens
Principal Tokens
Principal Tokens
Principal Tokens
Principal Tokens
Principal Tokens
Principal Tokens
IBT
Principal Tokens
Principal Tokens
IBT
Principal Tokens
Principal Tokens
Principal Tokens
Principal Tokens
IBT
Principal Tokens
Principal Tokens
IBT
Principal Tokens
Principal Tokens
IBT
IBT