Balmy
DCA
DCA
  • Introduction to the protocol
  • FAQ
  • Concepts
    • Positions
      • Actions
      • NFT/Permissions
      • Swap Intervals
    • Fees
    • Swaps
    • Token Integration
    • Yield Sources
  • Architecture
    • Core
      • Hub
      • Permission Manager
      • NFT Descriptor
    • Periphery
      • Companion
      • Libraries
  • Tech Guides
    • Interacting with the protocol
    • Smart Contract Registry
    • Swaps
      • Next Swap
      • Executing a Flash Swap
    • Position Management
      • Creating a Position
      • Modifying a Position
      • Withdrawing from a Position
      • Terminating a Position
    • Permission Management
    • Subgraphs
      • Playground
      • Fetch all pairs
      • Fetch all tokens
      • Fetch all active intervals
      • Fetch positions by address
    • Github
  • Mean explained by friends
    • By Perpetual Protocol
    • By Ceazor's Snack Sandwich
  • Other
    • Bug Reports
Powered by GitBook
On this page

Was this helpful?

  1. Tech Guides
  2. Position Management

Terminating a Position

When you are done with your position, you can terminate it. This action will send the unswapped and swapped balance to the specified recipients, and then it will destroy the position.

Please take into account that this action is irreversible. Once you terminate your position, you'll need to create a new one.

pragma solidity >=0.8.0 <0.9.0;

import '@mean-finance/dca-v2-core/contracts/interfaces/IDCAHub.sol';

contract MyContract {

    IDCAHub public immutable hub;
    
    constructor(IDCAHub _hub) {
        hub = _hub;
    }
    
    /// @notice Terminates the position and sends all unswapped and swapped balance to the specified recipients    
    /// @param _positionId The position's id
    /// @param _recipientUnswapped The address to withdraw unswapped tokens to
    /// @param _recipientSwapped The address to withdraw swapped tokens to
    /// @return _unswapped The unswapped balance sent to `_recipientUnswapped`
    /// @return _swapped The swapped balance sent to `_recipientSwapped`
    function terminate(
        uint256 _positionId,
        address _recipientUnswapped,
        address _recipientSwapped
    ) external returns (uint256 _unswapped, uint256 _swapped) {
        (_unswapped, _swapped) = hub.terminate(_positionId, _recipientUnswapped, _recipientSwapped);
    }
}
PreviousWithdrawing from a PositionNextPermission Management

Last updated 2 years ago

Was this helpful?