Dai - Detailed Documentation
The Dai Token Contract
Daicontract is the user-facing ERC20 token contract maintaining the accounting for external Dai balances. Most functions are standard for a token with changing supply, but it also notably features the ability to issue approvals for transfers based on signed messages.
Dai Interactions with the Maker Protocol
Key Functionalities (as defined in the smart contract)
Mint- Mint to an address
Burn- Burn at an address
Pull- Transfer From
Move- Transfer From
Approve- Allow pulls and moves
Permit- Approve by signature
name- Dai Stablecoin
totalSupply- Total DAI Supply
balanceOf(usr: address)- User balance
allowance(src: address, dst: address)- Approvals
nonces(usr: address)- Permit nonce
wad- fixed point decimal with 18 decimals (for basic quantities, e.g. balances).
For the most part,
dai.solfunctions as a typical ERC20 token. These tokens have been already been heavily documented here and it is recommended to read through that documentation for the core functions of an ERC20 token.
transferFromin the DAI contract works in a slightly different form than the generic
transferFromfunction. The DAI contract allows for "unlimited approval". Should the user approve an address for the maximum uint256 value, then that address will have unlimited approval until told otherwise.
moveare aliases for
transferFromcalls in the form of
transferFrom(msg.sender, usr, amount),
transferFrom(usr, msg.sender, amount)&
transferFrom(src, dst, amount).
permitis a signature-based approval function. This allows for an end-user to sign a message which can then be relayed by another party to submit their approval. This can be useful for applications in which the end-user does not need to hold
- In order to use this functionality, a user's address must sign a message with the
allowedamount. This can then be submitted to
Permit()to update the user's approval.
Unlimited allowance is a relatively uncommon practice (though becoming more common). This could be something used to trick a user by a malicious contract into giving access to all their DAI. This is concerning in upgradeable contracts where the contract may appear innocent until upgraded to a malicious contract.
DAI is also susceptible to the known ERC20 race condition, but should not normally be an issue with unlimited approval. We recommend any users using the
approvalfor a specific amount be aware of this particular issue and use caution when authorizing other contracts to perform transfers on their behalf.
There is a slight deviation in
transferFromfunctionality: If the
src == msg.senderthe function does not require
approvalfirst and treats it as a normal
The Dai token provides offchain approval, which means that as an owner of an ETH address, you can sign a permission (using the permit() function) which basically grants allowance to another ETH address. The ETH address that you provide permission to can then take care of the execution of the transfer but has an allowance.