SaveTokens
The logic (aka implementation) contract that the SaveTokenFactory uses to generate new SaveTokens with new interest-bearing asset and insurance token pairings.
SaveTokens are tokens that wrap together an interest-bearing asset and a commensurate amount of insurance tokens to create what we call a "self-insured asset".
The SaveTokenFactory contract is a clone factory, which deploys clones of the SaveToken logic (aka implementation) contract.
The SaveToken smart contract provides an interface to the Adapter contracts that execute actions on the interest-generating protocol and the insurance protocol used in a given SaveToken flavor. This interface allows for the following core functionality:
mint
mintmint is the function called when a saver deposits into a type of SaveToken.
function mint(uint256 amount) external returns (uint256)parameter:
amount, the number of SaveTokens to mintreturns: the number of SaveTokens minted
emits:
Mint, an event for indexing the number of SaveTokens mintedoutcome: mints SaveTokens, which are owned by
msg.sender
How mint works
mint worksDetermines the cost of the interest-bearing asset tokens
Determines the cost of the insurance tokens
Transfers the total amount of the underlying token (e.g., DAI, USDC, etc) necessary to mint the
amountof SaveTokensObtains the
assetTokensand theinsuranceTokensnecessary to mint theamountof SaveTokens via the corresponding asset adapter (as registered in the SaveToken contract).Mints the
amountof SaveTokens formsg.senderUpdates balances
The caller of mint must first approve the SaveToken contract to transfer their underlying token (e.g., DAI, USDC, etc.).
withdrawForUnderlyingAsset
withdrawForUnderlyingAssetwithdrawForUnderlyingAsset allows users to unbundle their SaveTokens and receive the underlying asset in return.
function withdrawForUnderlying(uint256 amount) externalparameter:
amount, the number of SaveTokens to unbundleemits:
WithdrawForUnderlyingAsset, an event for indexing the number of SaveTokens unbundledoutcome: Transfers underlying tokens returned to the
msg.sender
How withdrawForUnderlyingAsset works
withdrawForUnderlyingAsset worksWithdraws the underlying token in exchange for the interest-bearing asset token via the corresponding asset adapter (as registered in the SaveToken contract)
Exchanges the insurance token via the corresponding insurance adapter (as registered in the SaveToken contract) for the underlying token
Transfers the underlying token balance to
msg.senderUpdates balances
Burns the
amountof SaveTokens equal to theamountof tokens that were unbundled
exerciseInsurance
exerciseInsuranceexerciseInsurance allows users to exercise (aka make a claim on) their insurance, e.g. in case of an adverse financial event or a hack that reduces the value of the interest-bearing asset.
function exerciseInsurance(uint256 amount) externalparameter:
amount, the number of SaveTokens on which to exercise insuranceemits:
ExerciseInsurance, an event for indexing the number of SaveTokens in which insurance was exercisedoutcome: Transfers underlying balance returned from insurance protocol to
msg.sender
How exerciseInsurance works
exerciseInsurance worksThe SaveToken contract will exercise its insurance tokens or make an insurance claim via the SaveToken's corresponding insurance adapter (as registered in the SaveToken contract) on the user's behalf
Upon receiving the balance returned from exercising insurance, the SaveToken contract will transfer the balance to
msg.senderUpdates balances
Burns the
amountof SaveTokens equal to theamountof insurance tokens that were exercised
withdrawReward
withdrawRewardwithdrawReward allows users to withdraw all of the rewards tokens they've yielded through the corresponding interest-bearing asset protocol
function withdrawReward() external returns (uint256)emits:
WithdrawReward, an event for indexing the number of reward tokens withdrawnreturns: The
amountof reward tokens withdrawnoutcome: Transfers all rewards tokens yielded to
msg.sender
How withdrawReward works
withdrawReward worksVia the SaveToken's corresponding asset adapter (as registered in the SaveToken contract), the SaveToken contract will withdraw all of the rewards tokens they've yielded
The asset adapter, using a Rewards Farmer proxy, will claim the rewards tokens and transfer them to
msg.sender
Last updated