subtensor icon indicating copy to clipboard operation
subtensor copied to clipboard

Swap V3 tracking issue

Open ales-otf opened this issue 7 months ago • 0 comments

This issue is here to be in-sync and don't miss anything.

Working branch is feat/uniswapv3-lp.

Todo

  • [x] make FeeRate default to 196 (0.3 %)
  • [∞] clean up
  • [x] setup weights for Pallet::set_fee extrinsic
    • [x] add benchmarks
  • [ ] add more tests
  • [ ] optimize storage reads/writes
  • [x] connect to pallet-subtensor
    • [x] apply reserve and balance changes when add/remove liquidity or swap
    • [x] impl pallet-subtensor-swap-interface::SwapHandler for pallet-subtensor-swap::Pallet
    • [x] adapt this code, the values should be returned from SwapInterface::swap (Pallet::swap) and applied to reserves on the pallet-subtensor side. it was called within loop in swap
    /// Update token reserves after a swap
    fn update_reserves(netuid: NetUid, order_type: OrderType, amount_in: u64, amount_out: u64) {
        // TODO can we return the values from Self::swap, so the depender updated their state
        // (instead of us mutating it)
        // let (new_tao_reserve, new_alpha_reserve) = match order_type {
        //     OrderType::Sell => (
        //         self.state_ops.get_tao_reserve().saturating_add(amount_in),
        //         self.state_ops
        //             .get_alpha_reserve()
        //             .saturating_sub(amount_out),
        //     ),
        //     OrderType::Buy => (
        //         self.state_ops.get_tao_reserve().saturating_sub(amount_in),
        //         self.state_ops
        //             .get_alpha_reserve()
        //             .saturating_add(amount_out),
        //     ),
        // };

        // self.state_ops.set_tao_reserve(new_tao_reserve);
        // self.state_ops.set_alpha_reserve(new_alpha_reserve);
    }

ales-otf avatar Apr 02 '25 11:04 ales-otf