I have created a vault contract that has a deposit function that allows user to deposit any of the vault approved deposit asset and get a corresponding share of the vault token. I want the vault to be able to mint corresponding amount of vault toke If a user just transfers the token to the contract address. How do i accomplish this.
Feb 16, 2021, 5:48 AM
That's impossible. Transfers happen on the token contract, so that token contract's transfer()- or transferFrom()-function would have to have a call to your contract so that could work. But since that's not the case, there's no way to do that.
Feb 16, 2021, 9:48 AM
Why is it impossible? Actually its pretty easy
approve-transferFrom
Feb 16, 2021, 1:06 PM
Because when you send tokens to a contract, that contract does not know that it received tokens until the token contract sends an internal call to that contract notifying it about the transfer.
Example:
Contract 0x1 is the token contract with transfer() etc.
Contract 0x2 is a staking contract.
What the user wanted is that if I use transfer(0x2) on 0x1 (transfer tokens to 0x2), 0x2 reacts on that and for example sets up a stake. But since transfer() happens in 0x1, 0x2 will never know that it received tokens. It works like this: Approve 0x2 to spend tokens and then make the transferFrom() call in 0x2.
Example:
Contract 0x1 is the token contract with transfer() etc.
Contract 0x2 is a staking contract.
What the user wanted is that if I use transfer(0x2) on 0x1 (transfer tokens to 0x2), 0x2 reacts on that and for example sets up a stake. But since transfer() happens in 0x1, 0x2 will never know that it received tokens. It works like this: Approve 0x2 to spend tokens and then make the transferFrom() call in 0x2.
Feb 16, 2021, 2:31 PM
Yeah that's what I meant
...
Feb 16, 2021, 3:51 PM
Thats only possible with ERC777 tokens
So you can add a transfer hook
Or for tokens that implement the permit function, so u can take their signature to approve and use transferFrom
Feb 16, 2021, 3:54 PM
But that's not what the user wanted.
@mrrobot3_3
Basically the user wants a fallback like receive() or fallback() but for ERC20 tokens. This has to exist in the specific token but since ERC20 did not have this implemented, it does not exist.
Feb 16, 2021, 3:56 PM
"that has a deposit function". So just, include transferFrom in it?😅. Or did I get it wrong
Feb 16, 2021, 4:06 PM
Yes you did, you have to read till the end :D
Basically the user would like to bypass the approve()-requirement by a user simply sending tokens to that contract which the token would see and then credit to the user
Feb 16, 2021, 4:09 PM
Yup, saw it. Mb
Feb 16, 2021, 4:13 PM
Btw, guys, do you maybe know if there's an affordable personal coaching regarding dapps and solidity? I kind of struggle with for example truffle and react. What I need is someone who can be on spot when I have specific questions and help me introduce to i.e. UniSwap etc. Only chat would be needed. I tried Udemy but cannot really follow videos since they either go to basic or are like "ok and now we just paste this and that and btw. here also write this" without even explaining what's going on :D
Feb 16, 2021, 4:46 PM