Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bundled positions #89

Merged
merged 14 commits into from
Apr 7, 2023
Merged

Conversation

yugure-orca
Copy link
Collaborator

@yugure-orca yugure-orca commented Feb 20, 2023

Motivations

Some of the accounts created when a Whirlpool position is opened are not deleted when the position is closed. Therefore, the rent of accounts that are not deleted is an unrefundable cost.

In addition, the range (tick_lower_index and tick_upper_index) of a Whirlpool position cannot be changed after it has been opened, so a position must be closed and a new position opened if the range is to be changed. In other words, in order to change the range of a position, there is an overhead in the form of rent.

Some liquidity providers have a need to change the range of their positions frequently, and the rent overhead associated with changing the range of a position is not negligible and is a barrier to changing the range of a position.

Even if changes of range are infrequent, there is negative incentive to limit the creation of positions because of the unrefundable cost of each position. If the overhead of creating positions is eliminated, more positions can be used.

on-chain program updates

  • Move NFT name, symbol, metadata URI and UpdateAuthority definitions to constants (at util/token.rs before move)

  • Add account

    • PositionBundle
      • It can bundle 256 positions
      • an extra 64 bytes are reserved for future use
      • bundle_index is u16, so it can handle more positions

PositionBundleDiagram

  • Add instruction

    • initialize_position_bundle_with_metadata
      • Initialize PositionBundle account and mint an NFT.
      • Initialize Metadata only.
    • initialize_position_bundle
      • Initialize PositionBundle account and mint an NFT.
      • This instruction does NOT depend Metaplex TokenMetadata program.
    • delete_position_bundle
      • close PositionBundle account if it is empty (no opened Bundled Positions)
      • open_bundled_position instruction and close_bundled_position instruction allow delegation to authority.
        delete_position_bundle must be executed by the owner.
        The rented lamports can be refunded to receiver.
    • open_bundled_position
      • open Position and update the bitmap of PositionBundle account
    • close_bundled_position
      • close Position and update the bitmap of PositionBundle account
  • instruction update

    • close_position
      Add PDA seeds constraint to not close Bundled Position
  • new Position Bundle NFT is introduced

    • name: Orca Position Bundle xxxx...yyyy (xxxx and yyyy are the first and last 4 chars of mint address)
    • symbol: OPB
    • update authority: same to Position NFT

SDK updates

  • Update IDL (auto-generated)
  • Additions for PositionBundle account
    • add ParsablePositionBundle class
    • add methods to AccountFetcher
      • getPositionBundle
      • listPositionBundles
    • add methods to PDAUtil
      • getBundledPosition
      • getPositionBundle
      • getPositionBundleMetadata
  • add PositionBundleUtil class
  • add methods to WhirlpoolIx
    • initializePositionBundleIx
    • initializePositionBundleWithMetadataIx
    • deletePositionBundleIx
    • openBundledPositionIx
    • closeBundledPositionIx

Tests passed

integration

  • Check functionality of added instructions
  • Check error cases
    • Invalid account input
    • Invalid parameter input
    • Double open/close
  • Reject to close a non-empty Bundled Position
  • Reject to delete a non-empty PositionBundle
  • Unable to mint additional NFT
  • Confirmation that delegation works (open_bundled_position, close_bundled_position)
  • close_position cannot close a Bundled Position
  • close_bundled_position cannot close a (non-bundled) Position
  • close_position_bundle close PositionBundle and ATA accounts. (Mint and Metadata accounts are NOT closable)

Integration/multi-ix

  • increase/decreaseLiquidity, updateFeesAndRewards, collectFees, and collectReward work for Bundled Position
  • all 256 BundledPositions can be opened
  • open + close + open + close for the same bundled_index (separate transaction)
  • open/close within a single Tx
  • open/increase/swap/decrease/collectFee/close within a single Tx
  • Cannot open/close + re-open in a single Tx

sdk

  • Check each function of PositionBundleUtil

dovahcrow and others added 8 commits March 2, 2023 22:48
use mpl-token-metadata 1.7 because rust 1.60 does not compile 1.8
- initialize_pool.test: update error codes, add a test case for ignoring bump
- ProgramResult to Result<()>
- add /// CHECK comments
- remove space attribute on Mint account
- change create_metadata_accounts_v2 to v3
- update testcases
  - Change in error code detected first
  - Change in account closing method
    coral-xyz/anchor#2169
@staccDOTsol

This comment was marked as spam.

@staccDOTsol

This comment was marked as spam.

doc fields are added on IDL
Fixed test cases that did not take into account rewards accruing up to just before the close.
This test case is not related to bundled positions.
The test case happened to fail, so I fixed them to make them all successful.
Copy link
Contributor

@rawfalafel rawfalafel left a comment

Choose a reason for hiding this comment

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

LGTM!

@yugure-orca yugure-orca merged commit 44021b1 into orca-so:main Apr 7, 2023
@yugure-orca yugure-orca mentioned this pull request Apr 7, 2023
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.

4 participants