Vault math th-cam.com/video/k7WNibJOBXE/w-d-xo.html 0:00 - State variables and constructor 1:20 - Internal functions - mint and burn 2:32 - deposit 5:00 - withdraw 6:34 - Deploy and demo Code solidity-by-example.org/defi/vault Take a course www.smartcontract.engineer/
It's worth considering what happens when your numbers don't divide evenly, in this example you doubled the tokens so it boiled down to a division of 2000/1000 =2/1=2. It's also worth considering what happens when the user puts in some more tokens after they put in the initial 1000, and how that might affect things given integer rounding errors. Also you can try having multiple users put in tokens and see how that goes.
hey man just a question, any recommendations how to brush up on my general DeFi knowledge? I am okay with the coding part but some defi knowledge like shares/token amount is a bit alien to me. Thanks!
I want to give specific amount reward for each depositor lets say 1% per day per users on the smart contract internally? how can i add it on the code as function?
This contract may be abstract, it may not implement an abstract parent's methods completely or it may not invoke an inherited contract's constructor correctly. I'm getting this error while importing IERC20.sol what to do?, please explain.
Its what you can do with the erc-20 receipt tokens, for example, you can transfer them to a lending contract that lets you borrow against them or lock them as a bond to sell to other users, etc...
Thanks for the fantastic content! Could you suggest some projects for people who know a bit of Solidity and want to delve deeper into the world of DeFi?
Great video. I am new to Solidity. Out of curiousity, why do you use transfer() instead of call() which is mentioned by many best practices that call() is the better transaction method to go with?
It is from the above mentioned formula - s = (a * T) / B where: a = amount of tokens to deposit; T = total supply of shares before deposit; B = balance of tokens held by the vault contract this is how you get the amount of shares you would receive per x deposited tokens.
Vault math
th-cam.com/video/k7WNibJOBXE/w-d-xo.html
0:00 - State variables and constructor
1:20 - Internal functions - mint and burn
2:32 - deposit
5:00 - withdraw
6:34 - Deploy and demo
Code
solidity-by-example.org/defi/vault
Take a course
www.smartcontract.engineer/
This is GOLD! Thank you
Thank you, exactly what I was waiting for.
as always awesome
It's worth considering what happens when your numbers don't divide evenly, in this example you doubled the tokens so it boiled down to a division of 2000/1000 =2/1=2. It's also worth considering what happens when the user puts in some more tokens after they put in the initial 1000, and how that might affect things given integer rounding errors. Also you can try having multiple users put in tokens and see how that goes.
usually rounding errors are circumvented by having 18 decimals
@@smartcontractprogrammer I'm actually deal with it in my project .
Maybe you have some kind of solution?
Libraries , tricks , etc.
this was awesome
Hi , Please cover ERC-4626
hey man just a question, any recommendations how to brush up on my general DeFi knowledge? I am okay with the coding part but some defi knowledge like shares/token amount is a bit alien to me. Thanks!
Hey can you explain what is the purpose of a vault contract? Im not sure I understand
collecting tokens and utilized by contract owner
for example, collect DAI from users, contract owner deposits it into Curve to earn fee and rewards
I want to give specific amount reward for each depositor lets say 1% per day per users on the smart contract internally? how can i add it on the code as function?
Love from india 😍
This contract may be abstract, it may not implement an abstract parent's methods completely or it may not invoke an inherited contract's constructor correctly.
I'm getting this error while importing IERC20.sol
what to do?, please explain.
what's the advantage of issuing the erc-20 receipt tokens when you could just increment a uint?
I’m also interested in the answer.
Its what you can do with the erc-20 receipt tokens, for example, you can transfer them to a lending contract that lets you borrow against them or lock them as a bond to sell to other users, etc...
@@lukefoster5990 thanks.
It's just like a bond (IOU)
If the vault is trusted on other ecosystems like uniswap or aave or compound, you can keep your bond/IOU as collateral.
Thanks for the fantastic content! Could you suggest some projects for people who know a bit of Solidity and want to delve deeper into the world of DeFi?
Yearn
Uniswap
Curve
Aave
Compound
Frax
Alchemix
Chainlink
Nice, can you make a video for testing with hardhat
I'm developing the vault protocol on Solana. Do you have any good resources you've found that I can refer to?
Sorry, no. I've never coded on Solana
@smartcontractprogrammer: I don't understand B in the formula, please explain to me ?
B = balance of token before transferFrom is called
Great video.
I am new to Solidity. Out of curiousity, why do you use transfer() instead of call() which is mentioned by many best practices that call() is the better transaction method to go with?
it's ERC20 transfer, not ETH transfer
what is shares = _amount means?, How this is possible?. Please explain.
This is also not clear to me, so, will be happy to know for what these shares are used and why it works like that.
It is from the above mentioned formula - s = (a * T) / B
where:
a = amount of tokens to deposit;
T = total supply of shares before deposit;
B = balance of tokens held by the vault contract
this is how you get the amount of shares you would receive per x deposited tokens.
Great video
in deposit you should NOT mint before receiving the token from the user.
Way we derived the equation, we must mint before deposit.
It's also best practice to update state variables before calling external contracts
is there make sens to return bool for deposit & withdraw?
Personal opinion, no
@@smartcontractprogrammer thanks
why not use the ERC 4626 standard for this?
Focusing on math, not standards