Principal Token
Last updated
Last updated
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 .
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.
assets
uint256
The amount of the underlying assets to deposit.
receiver
address
shares
uint256
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.
assets
uint256
The amount of the underlying assets to deposit.
ptReceiver
address
ytReceiver
address
shares
uint256
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.
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
shares
uint256
msg.sender
must approve the relevant allowance of the IBT before calling this method.
ibts
uint256
The amount of the PrincipalToken's IBT assets to deposit.
receiver
address
shares
uint256
msg.sender
must approve the relevant allowance of the IBT before calling this method.
ibts
uint256
The amount of the PrincipalToken's IBT assets to deposit.
ptReceiver
address
ytReceiver
address
shares
uint256
msg.sender
must approve the relevant allowance of the IBT before calling this method.
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
shares
uint256
shares
uint256
receiver
address
owner
address
assets
uint256
I.e. converts PT to the underlying asset, using the number of PT to burn, after expiry.
shares
uint256
receiver
address
owner
address
minAssets
uint256
The minimum asset amount that the caller expects the receiver
to receive.
assets
uint256
shares
uint256
receiver
address
The address that will receive the redeemed tokens.
owner
address
ibts
uint256
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.
ibts
uint256
assets
uint256
receiver
address
owner
address
shares
uint256
I.e. converts PT and YT to the underlying asset, using the number of underlying assets to withdraw, before expiry.
assets
uint256
receiver
address
owner
address
maxShares
uint256
The maximum amount of shares allowed to be burnt
shares
uint256
ibts
uint256
receiver
address
The address that will receive the withdrawn tokens.
owner
address
shares
uint256
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
shares
uint256
Claims the yield of msg.sender
based on their current balance of YT. Send the yield as underlying tokens.
_receiver
address
The address that will receive the yield.
yieldInAsset
uint256
_receiver
address
The address that will receive the yield.
yieldInIBT
uint256
Updates _user
yield with the latest yield in IBT generated since the previous update.
_user
address
The address of the user to compute the yield
updatedUserYieldInRay
uint256
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.
_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.
bool
If successful, flashLoan
return true
.
Store the rates at the time of expiry.
Calculates the amount of principal tokens that are equivalent to the amount of underlyingAmount
.
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.
Returns the total duration of the principal token period in seconds.
E.g. if the underlying asset is DAI, the IBT could be aDAI (for Aave deposited DAI) or cDAI (for Compound deposited DAI), etc.
Returns the ibtRate.
Returns the ptRate.
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.