Skip to content

feat: add DCL liquidity management module - #1

Open
Kampouse wants to merge 1 commit into
ref-finance:mainfrom
Kampouse:main
Open

feat: add DCL liquidity management module#1
Kampouse wants to merge 1 commit into
ref-finance:mainfrom
Kampouse:main

Conversation

@Kampouse

Copy link
Copy Markdown

Summary

Adds dcl-liquidity.ts with concentrated liquidity position management for the CLMM contract (dclv2.ref-labs.near).

All methods are tested on NEAR mainnet with real transactions:

Method Contract Call Tested
depositTokenToCLMM() ft_transfer_call(msg: "Deposit")
addLiquidity() batch_add_liquidity direct call
removeLiquidity() remove_liquidity (amount="0" = fee harvest)
getLiquidityPositions() nft_tokens_for_owner (view)
openPosition() Convenience: register + deposit + add

What this enables

  1. Open LP positions — deposit tokens, add liquidity at specific price ranges
  2. Harvest feesremove_liquidity(amount="0") claims accrued fees without closing the position
  3. Close positionsremove_liquidity(amount=full) with auto-fee-claim
  4. Range management — query positions, remove + re-deploy when price drifts (auto-churn bots)

Key discoveries (documented)

  • CLMM uses internal balance system: tokens must be deposited via ft_transfer_call("Deposit") before batch_add_liquidity can use them
  • Fee harvest = remove_liquidity with amount: "0" — no separate harvest method exists
  • LP positions are NFTs tracked via nft_tokens_for_owner, not list_active_orders
  • Ticks must be bin-aligned (multiples of point_delta, e.g. 200 for 1% fee pools)

Files added

  • src/dcl-swap/dcl-liquidity.ts — 348 lines, full liquidity management
  • src/index.ts — export added

Checklist

  • All methods tested on mainnet
  • Follows existing SDK patterns (uses refDCLSwapViewFunction, DCLSwapGetStorageBalance, etc.)
  • TypeScript interfaces for all params
  • JSDoc documentation on public functions
  • Unit tests (happy to add if template is provided)

Adds dcl-liquidity.ts with concentrated liquidity position management
for the CLMM contract (dclv2.ref-labs.near).

All methods tested on NEAR mainnet:

- depositTokenToCLMM(): ft_transfer_call('Deposit') to store tokens
  in CLMM internal balance before adding liquidity

- addLiquidity(): batch_add_liquidity direct call with pool_id,
  amount_x/y, left_point, right_point, min_amount_x/y

- removeLiquidity(): remove_liquidity with lpt_id, amount, liquidate_type
  - amount='0' harvests fees only (position stays open)
  - amount=full closes position + claims principal

- getLiquidityPositions(): nft_tokens_for_owner enumeration to find
  all LP NFT positions for an account

- openPosition(): convenience function combining storage registration,
  token deposit, and batch_add_liquidity in a single transaction set

Fee tiers documented as 1% (fee=100) with point_delta=200 requiring
bin-aligned tick values (multiples of 200).
@Kampouse

Copy link
Copy Markdown
Author

since no one ever did it here an example on how it could be done for the clmm
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant