Place Long Term Order

Details on how to place long term order

How to place long term order?

Using API

Long term order can be placed by calling JoinPool on the balancer vault. Here is how JoinPool looks like:

joinPool(
    bytes32 poolId,
    address sender,
    address recipient,
    JoinPoolRequest request
)

struct JoinPoolRequest {
    address[] assets,
    uint256[] maxAmountsIn,
    bytes userData,
    bool fromInternalBalance
}

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

API request param details

Here is a sample way to create userData in javascript.

  const encodedPlaceLongTermOrderRequest = defaultAbiCoder.encode(
    ['uint256', 'uint256', 'uint256', 'uint256', 'uint256'],
    [4, tokenInIndex, tokenOutIndex, amountIn, numberOfBlockIntervals]
  );

The first parameter in the request data is always 4, which corresponds to the place long term order(PLACE_LONG_TERM_ORDER) JoinKind. Other request parameter details are as follows:

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

  • tokenOutIndex: 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.

  • amountIn: This is the token amount of tokenInIndex to be sold.

  • numberOfBlockIntervals: This the number of block intervals for which the order will be active in the AMM. See here for details on how this will impact the order time.

LongTermOrderPlaced

LongTermOrderPlaced event is emitted when the order is placed successfully.

event LongTermOrderPlaced(
    uint256 orderId,
    uint256 indexed buyTokenIndex,
    uint256 indexed sellTokenIndex,
    uint256 saleRate,
    address indexed owner,
    uint256 expirationBlock
);

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.

Order life time

Details on how the order life is calculated

Place transaction using UI

  1. Go to app.longswap.xyz.

  2. Go to Long Term Swap tab.

  3. Choose pair, amounts, duration.

  4. (One time) approve Balancer vault to spend your tokens.

  5. Place a Long term order.

  6. Once the order is placed, it should show up in the orders list in the same tab.

Last updated