Last active
March 8, 2023 19:48
-
-
Save sekrystal/855e764fd9af8f10fb67653ec145abf5 to your computer and use it in GitHub Desktop.
Defi Lending Concepts 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.8.13; | |
function deposit(uint subAccountId, uint amount) external nonReentrant { | |
(address underlying, AssetStorage storage assetStorage, address proxyAddr, address msgSender) = CALLER(); | |
address account = getSubAccount(msgSender, subAccountId); | |
updateAverageLiquidity(account); | |
emit RequestDeposit(account, amount); | |
AssetCache memory assetCache = loadAssetCache(underlying, assetStorage); | |
if (amount == type(uint).max) { | |
amount = callBalanceOf(assetCache, msgSender); | |
} | |
amount = decodeExternalAmount(assetCache, amount); | |
uint amountTransferred = pullTokens(assetCache, msgSender, amount); | |
uint amountInternal; | |
unchecked { | |
assetCache.poolSize -= amountTransferred; | |
amountInternal = underlyingAmountToBalance(assetCache, amountTransferred); | |
assetCache.poolSize += amountTransferred; | |
} | |
increaseBalance(assetStorage, assetCache, proxyAddr, account, amountInternal); | |
if (assetStorage.users[account].owed != 0) checkLiquidity(account); | |
logAssetStatus(assetCache); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment