sUSDS Token
Savings USDS and the Sky Savings Rate are non-custodial and permissionless smart contracts offered by Sky, and is not issued by Spark. Spark does not have any control over the Sky Savings Rate or the sUSDS token.
Contract Name: SUsds.sol
Type/Category: SSR
Contract Source: sUSDS code repository
Ethereum Contract Address: 0xa3931d71877C0E7a3148CB7Eb4463524FEc27fbD
1. Introduction (Summary)
Savings USDS (sUSDS) is an ERC-4626 representation/wrapper of USDS in the Sky Savings Rate module (SSR). sUSDS allows users to deposit USDS to receive the yield generated by the Sky Protocol while still being able to transfer, stake, lend and any other use cases. Converting between USDS and sUSDS can be done using the ERC4626 interface.
2. Contract Details
Variables
name
: Savings USDSsymbol
: sUSDSversion
: 1decimals
: 18totalSupply
: An unsigned integer representing the total supply of the token. It keeps track of the total number of tokens in circulation.balanceOf
: A mapping that associates an address with its corresponding token balance. It allows for looking up the balance of a specific address.allowance
: A nested mapping that associates an owner address with a spender address and their approved token allowance. It allows an owner to specify how many tokens a specific spender is allowed to transfer on their behalf.nonces
: A mapping that associates an address with its corresponding permit nonce. It is used for the EIP712 permit functionality, allowing an address to sign permit messages with a unique nonce.
ERC20 token functionality
The contract implements the functions specified in the ERC-20 interface.
transfer
: Transfers a specified amount of tokens from the caller's address to the specified recipient's address. It returns a boolean value indicating the success of the transfer.transferFrom
: Transfers a specified amount of tokens from thefrom
address to theto
address. The transfer must be allowed by thefrom
address by calling theapprove
function or by setting an allowance. It returns a boolean value indicating the success of the transfer.approve
: Sets an allowance for a specific spender to spend a certain amount of tokens on behalf of the caller. It returns a boolean value indicating the success of the approval.increaseAllowance
: Increases the allowance granted to a specific spender by adding theaddedValue
to the current allowance. It returns a boolean value indicating the success of the operation.decreaseAllowance
: Decreases the allowance granted to a specific spender by subtracting thesubtractedValue
from the current allowance. It returns a boolean value indicating the success of the operation.
ERC4626 token functionality
The contract implements the functions specified in the ERC-4626 interface.
asset
: This function returns the address of the underlying asset (USDS) associated with the Savings USDS token.totalAssets
: This function returns the total value of assets held by the Savings USDS token, calculated based on the total supply of shares.convertToShares
: This function converts the specified amount of assets into the corresponding number of shares based on the current exchange rate.convertToAssets
: This function converts the specified number of shares into the corresponding amount of assets based on the current exchange rate.maxDeposit
: This function returns the maximum amount of assets that can be deposited into the Savings USDS contract.previewDeposit
: This function calculates and returns the number of shares that would be minted for the specified amount of assets upon deposit.deposit
: This function allows users to deposit a specified amount of assets into the Savings USDS contract and mints the corresponding number of shares.maxMint
: This function returns the maximum number of shares that can be minted by an address.previewMint
: This function calculates and returns the amount of assets that would be minted for the specified number of shares upon minting.mint
: This function allows users to mint a specified number of shares and receives the corresponding amount of assets.maxWithdraw
: This function returns the maximum amount of assets that can be withdrawn by the specified owner address.previewWithdraw
: This function calculates and returns the number of shares that would be burned for the specified amount of assets upon withdrawal.withdraw
: This function allows the owner to withdraw a specified amount of assets, burns the corresponding number of shares, and transfers the assets to the receiver address.maxRedeem
: This function returns the maximum number of shares that can be redeemed by the specified owner address.previewRedeem
: This function calculates and returns the amount of assets that would be redeemed for the specified number of shares upon redemption.redeem
: This function allows the owner to redeem a specified number of shares, transfers the corresponding amount of assets to the receiver address, and burns the redeemed shares.permit
: This function allows the owner to approve a permit for the spender to spend a specific amount of tokens on their behalf, using a signature for authorization.permit
: This overloaded version of thepermit
function accepts the signature parameters (v, r, s) individually instead of a signature byte array.
Referral Code
The deposit
and mint
functions accept an optional uint16 referral
parameter that frontends can use to mark deposits as originating from them. Such deposits emit a Referral(uint16 indexed referral, address indexed owner, uint256 assets, uint256 shares)
event. This could be used to implement a revshare campaign, in which case the off-chain calculation scheme will likely need to keep track of any Transfer
and Withdraw
events following a Referral
for a given token owner.
Upgradeability
The contract uses the ERC-1822 UUPS pattern for upgradeability and the ERC-1967 proxy storage slots standard. It is important that the SUsdsDeploy
library sequence be used for deploying.
Events emitted
Approval
: This event is emitted when an approval is set for a specific address. It indicates that the owner has approved the spender to spend a certain amount of tokens.Deposit
: This event is emitted when a deposit is made into the Savings USDS contract. It indicates the sender, the owner of the deposited assets, the amount of assets deposited, and the corresponding shares minted.Transfer
: This event is emitted when tokens are transferred from one address to another. It indicates the amount of tokens transferred and the addresses involved in the transfer.Withdraw
: This event is emitted when a withdrawal is made from the Savings USDS contract. It indicates the sender, the receiver of the withdrawn assets, the owner of the withdrawn shares, the amount of assets withdrawn, and the corresponding shares burned.
3. Key Mechanisms & Concepts
While the aim of USDS is to always be worth 1 USD, sUSDS is constantly increasing in value due to the accumulation of the yield. In order to have a good UX when sending funds, you can use the view function ConvertToShares
which will take USDS as input and output the sUSDS amount.
4. Gotchas / Integration Concerns
No
Transfer
event at mint/burn
ERC4626 specifies a Deposit
and Withdraw
event which is more verbose than the ERC20 Transfer
event. In the short term this has a negative effects with integrations of dapps as most only register Transfer
events, ignoring Deposit
and Withdraw
. Long term, it makes sense for dapps to consider the richer events and avoid unnecessary gas use for the redundant event.
5. Useful links
Last updated