Skip to content

add alpha pool contract#2072

Merged
sam0x17 merged 13 commits intodevnet-readyfrom
alpha_pool_contract
Oct 1, 2025
Merged

add alpha pool contract#2072
sam0x17 merged 13 commits intodevnet-readyfrom
alpha_pool_contract

Conversation

@open-junius
Copy link
Contributor

Description

Add an alpha pool contract to show alpha transfer and delegatecall usage.

Related Issue(s)

  • Closes #[issue number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

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

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (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.

@open-junius open-junius self-assigned this Sep 22, 2025
@open-junius open-junius marked this pull request as ready for review September 29, 2025 03:19
@open-junius open-junius added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Sep 29, 2025
Comment on lines 25 to 26
require(contract_hotkey != 0x00, "contract coldkey not set");

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
require(contract_hotkey != 0x00, "contract coldkey not set");
require(contract_hotkey != 0x00, "contract coldkey not set");

Coldkey or hotkey?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is coldkey, will fix it. the hotkey should be set in constructor.

Comment on lines 24 to 51
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, will check if any swap fee happened.

contract_coldkey = _contract_coldkey;
}

function depositAlpha(uint256 _netuid, uint256 _alphyAmount, bytes32 _hotkey) public {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +98 to +103

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should test the deposit flow include the transferStake by a depositing coldkey

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sam0x17 sam0x17 merged commit a3cc69c into devnet-ready Oct 1, 2025
56 checks passed
@sam0x17 sam0x17 mentioned this pull request Oct 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-cargo-audit This PR fails cargo audit but needs to be merged anyway

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants