Skip to content

Swap-Subnet/buyback

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SN10 Buyback Contract

Collects Uniswap V3 protocol fees and stakes them on Bittensor SN10.

Setup

yarn install

Note: Requires Node.js 22+ for Hardhat 3

Deployment (Ignition)

  1. Derive the treasury coldkey from the treasury EVM address:
    yarn derive:coldkey 0xd7370E4E7637b040EA1C2EB6a13447fC65448C23
    Copy the output (a 32-byte hex string) into the treasuryColdkey field.
  2. Populate ignition/parameters.json with:
    • poolAddress – the Uniswap V3 pool
    • treasuryAddress – the treasury EVM account
    • treasuryColdkey – the derived value from step 1
    • stakingHotkey – the validator hotkey
  3. Deploy with Ignition:
    yarn hardhat ignition deploy ./ignition/modules/Buyback.ts \
      --network bittensor_mainnet \
      --parameters ignition/parameters.json

Usage

Treasury workflow:

  1. Collect protocol fees from Uniswap pool (external)
  2. Send collected tokens to Buyback contract
  3. Call buyback(limitPriceRao, allowPartial) to:
    • Swap token1 → token0 if needed
    • Stake tokens to the configured hotkey via the staking precompile
  4. Call collectStake() to move the accumulated stake to the treasury coldkey

Testing

  • Start a Hardhat fork of Bittensor mainnet (for example: yarn hardhat node --fork $BITTENSOR_RPC --fork-block-number <block>).
  • In a separate terminal run the suite against that fork: yarn hardhat test --network localhost.
  • The tests interact with the real Uniswap pool, so keep the fork in sync with the block used above.

Post-deployment

If you deploy manually without Ignition, call:

  1. setTreasury(address, bytes32) with the treasury address and derived coldkey.
  2. setStakingHotkey(bytes32) with the validator hotkey.
  3. setBuybackColdkey(bytes32) with the coldkey derived from the Buyback contract address.

Dependencies

  • @openzeppelin/contracts 5.4.0
  • @uniswap/v3-core
  • Hardhat 3 Beta

About

buyback contract for sn10 alpha tokens

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors