Conversation
| require(contract_hotkey != 0x00, "contract coldkey not set"); | ||
|
|
There was a problem hiding this comment.
| require(contract_hotkey != 0x00, "contract coldkey not set"); | |
| require(contract_hotkey != 0x00, "contract coldkey not set"); |
Coldkey or hotkey?
There was a problem hiding this comment.
It is coldkey, will fix it. the hotkey should be set in constructor.
| function depositAlpha(uint256 _netuid, uint256 _alphyAmount, bytes32 _hotkey) public { | ||
| require(contract_hotkey != 0x00, "contract coldkey not set"); | ||
|
|
||
| bytes memory data = abi.encodeWithSelector( | ||
| IStaking.transferStake.selector, | ||
| contract_coldkey, | ||
| _hotkey, | ||
| _netuid, | ||
| _netuid, | ||
| _alphyAmount | ||
| ); | ||
| (bool success, ) = address(ISTAKING_V2_ADDRESS).delegatecall{gas: gasleft()}(data); | ||
| require(success, "user deposit alpha call failed"); | ||
|
|
||
| if (_hotkey != contract_hotkey) { | ||
| data = abi.encodeWithSelector( | ||
| IStaking.moveStake.selector, | ||
| _hotkey, | ||
| contract_hotkey, | ||
| _netuid, | ||
| _netuid, | ||
| _alphyAmount | ||
| ); | ||
| (success, ) = address(ISTAKING_V2_ADDRESS).call{gas: gasleft()}(data); | ||
| require(success, "user deposit, move stake call failed"); | ||
| } | ||
|
|
||
| alphaBalance[msg.sender][_netuid] += _alphyAmount; |
There was a problem hiding this comment.
if the transfer charges a fee it's possible that the contract will receive less than alphaAmount_.
Should maybe take the diff of the alpha before and after the transfer call
There was a problem hiding this comment.
make sense, will check if any swap fee happened.
| contract_coldkey = _contract_coldkey; | ||
| } | ||
|
|
||
| function depositAlpha(uint256 _netuid, uint256 _alphyAmount, bytes32 _hotkey) public { |
There was a problem hiding this comment.
how does the deposit work?
I assume the user needs to call transferStake on a deposit_hotkey (_hotkey) to the contract_coldkey before calling this function
There was a problem hiding this comment.
transferStake just called via the delegatecall in the depositAlpha function. If user call it directly, not in the contract, the contract can't aware the transfer.
|
|
||
| const depositAlphaTx = await contractForCall.depositAlpha(netuid, tao(10).toString(), hotkey.publicKey) | ||
| await depositAlphaTx.wait() | ||
|
|
||
| // compare wallet stake | ||
| const stakeAftereDeposit = await api.query.SubtensorModule.Alpha.getValue(convertPublicKeyToSs58(hotkey.publicKey), convertH160ToSS58(wallet.address), netuid) |
There was a problem hiding this comment.
should test the deposit flow include the transferStake by a depositing coldkey
There was a problem hiding this comment.
I think it is not necessary. That is the purpose for this contract and the added test. Based on the solution, the developer can build alpha pool in the contract.
Description
Add an alpha pool contract to show alpha transfer and delegatecall usage.
Related Issue(s)
Type of Change
Breaking Change
If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.
Checklist
cargo fmtandcargo clippyto ensure my code is formatted and linted correctlyScreenshots (if applicable)
Please include any relevant screenshots or GIFs that demonstrate the changes made.
Additional Notes
Please provide any additional information or context that may be helpful for reviewers.