joinPool function on the BEX Vault.
joinPool function
Arguments explained
JoinPoolRequest struct
Token ordering
When providing assets, tokens must be sorted numerically by address. The values inmaxAmountsIn correspond to the same index in assets, so these arrays must be created in parallel after sorting.
Maximum amounts
ThemaxAmountsIn parameter sets upper limits for tokens to send. This protects against price changes between transaction submission and execution.
Best practice:
- Use
queryJointo calculate current token amounts needed - Add slippage tolerance (e.g., multiply by 1.01 for 1% slippage)
- Use these adjusted amounts as
maxAmountsIn
userData encoding
TheuserData field encodes the join type and parameters. Different pool types support different join kinds.
JoinKind enum
When encoding
userData for pools that include their own LP token, the LP tokens are not included
except for INIT joins.userData encoding
Examples
Example 1: Initial join (INIT)
Seeding a new pool with$BERA and $HONEY:
Example 2: Exact tokens join (EXACT_TOKENS_IN_FOR_LP_OUT)
Joining an existing BERA/HONEY pool:Example 3: Single token join (TOKEN_IN_FOR_EXACT_LP_OUT)
Joining a$BERA/$HONEY/$DAI pool with only $BERA: