Add transferStakeFrom and approve functions to staking precompile#2478
Add transferStakeFrom and approve functions to staking precompile#2478jeremyp-tao wants to merge 6 commits intoopentensor:devnet-readyfrom
transferStakeFrom and approve functions to staking precompile#2478Conversation
| } | ||
|
|
||
| #[precompile::public("increaseAllowance(bytes32,uint256,uint256)")] | ||
| fn increase_allowance( |
There was a problem hiding this comment.
We can use approve interface to do increase/decrease allowance, and they are not in the standard ERC20 definition.
There was a problem hiding this comment.
Contracts can easily get the current allowance and increase it atomically (they must check for re-entrancy attacks), however users cannot do that. That's why those functions are very common in tokens implementing ERC20.
|
It is better to implement both function in an Alpha wrapper contract, instead of in precompile. @ppolewicz @camfairchild any update for ERC20-alpha-wrapper |
| <R as frame_system::Config>::AccountId, | ||
| // For each pair of (spender, netuid) | ||
| Blake2_128Concat, | ||
| (<R as frame_system::Config>::AccountId, u16), |
There was a problem hiding this comment.
What happens on subnet de-reg?
There was a problem hiding this comment.
I'm not sure a de-reg would cause any issue. There approve would still be here but the user can update the allowance at anytime, and is suppose to trust/verify that the contract will do appropriate things with the approved funds. So I think it is not worth it to complicate the design.
Description
Adds new functions to the staking precompile similar to ERC20
transferFromandapprove, which will allow smart contracts to atomically receive alpha tokens and react to the transfer, which is not possible today (if an user transfers alpha token to a smart contract, the latter is not aware of this transfer). Allowance is managed per netuid for finer control.Related Issue(s)
None
Type of Change
Breaking Change
None
Checklist
./scripts/fix_rust.shto ensure my code is formatted and linted correctlyScreenshots (if applicable)
Not applicable
Additional Notes
None