Skip to content

sDAI Token

Overview

Savings Dai (sDAI) is an ERC-4626 representation/wrapper of DAI in the Dai Savings Rate module (DSR). sDAI allows users to deposit DAI to receive the yield generated by the Sky Protocol while still being able to transfer, stake, lend and any other use cases.

Contract Details

Variables

  • name: Savings Dai
  • symbol: sDAI
  • version: 1
  • decimals: 18
  • totalSupply: 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 the from address to the to address. The transfer must be allowed by the from address by calling the approve 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 the addedValue 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 the subtractedValue 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 (DAI) associated with the SavingsDai token.
  • totalAssets: This function returns the total value of assets held by the SavingsDai 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 SavingsDai 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 SavingsDai 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 the permit function accepts the signature parameters (v, r, s) individually instead of a signature byte array.

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 SavingsDai 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 SavingsDai 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.

Key Mechanisms & Concepts

While the aim of DAI is to always be worth 1 USD, sDAI is constantly increasing 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 DAI as input and output the sDAI amount.

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.

Additional resources