Withdraw Long Term Order

Details on how to withdraw long term order

How to withdraw long term order?

Using API

Withdraw long term order can be placed by calling ExitPool on the balancer vault. Here is how ExitPool looks like:

    bytes32 poolId,
    address sender,
    address recipient,
    ExitPoolRequest request

struct ExitPoolRequest {
    address[] assets,
    uint256[] minAmountsOut,
    bytes userData,
    bool toInternalBalance

You can find complete details here. All the details remains same as ExitPool, only changes are in the way userData in ExitPoolRequest is constructed.

Request param details

Here is a sample way to create userData in javascript.

const encodedWithdrawOrderRequest = defaultAbiCoder.encode(['uint256', 'uint256'], [5, orderId]);

The first parameter in the request data is always 5, which corresponds to the withdraw long term order(WITHDRAW_LONG_TERM_ORDER) ExitKind. Other request parameter details are as follows:

  • orderId: This is the orderId which you received when you placed long term order request.


  1. The sender parameter in the request should be same as the recipient parameter in place long term order request.

  2. In case the order is not complete the partial withdrawal happens.


LongTermOrderWithdrawn event is emitted when the order is withdrawn successfully.

event LongTermOrderWithdrawn(
    uint256 orderId,
    uint256 indexed buyTokenIndex,
    uint256 indexed sellTokenIndex,
    uint256 saleRate,
    address indexed owner,
    uint256 expirationBlock,
    uint256 proceeds,
    bool isPartialWithdrawal

Details available in the events:

  • orderId: Represents the id of the order in the contract, this can be used to withdraw, cancel or to get the long term order details.

  • buyTokenIndex: This is the index of the pool token user wants to buy. Check this Vault API to get list of tokens and corresponding token index to use.

  • sellTokenIndex: This is the index of the pool token placed for sell. Check this Vault API to get list of tokens and corresponding token index to use.

  • saleRate: This represents the sale rate per block of the sell token.

  • owner: The details of the user placing the order.

  • expirationBlock: The block at which the order will expire.

  • proceeds: The sale proceeds from the order.

  • isPartialWithdrawal: Flag, if the withdrawal was partial or not.

Partial Withdrawal

It is possible that the order is not completed when user placed withdraw long term order request. In such case whatever the amount converted till the point withdraw request was received is withdrawn to the recipient wallet. The rest of the order continues as is.

Place transaction using UI

  1. Go to app.longswap.xyz.

  2. Go to Long Term Swap tab.

  3. Once the order history loads, go to the order card which you want to withdraw.

  4. Click on Withdraw and confirm the request from your wallet.

  5. Verify the order is withdrawn.

Last updated