Skip to main content

Function: bidirectionalTokenMatch()

Gala Launchpad SDK 9.0.0-rc.5


Gala Launchpad SDK 9.0.0-rc.5 / index / bidirectionalTokenMatch

Function: bidirectionalTokenMatch()

bidirectionalTokenMatch(token0, token1, tokenA, tokenB): boolean

Defined in: packages/launchpad-sdk/dist/utils/string-patterns.d.ts:280

Check if two token pairs match in either order (bidirectional).

Compares two pairs of tokens to see if they represent the same pair, accounting for different orderings (A,B matches B,A). Essential for pool pair matching in DEX operations.

Consolidated from 4 duplicated patterns in bidirectional token matching:

  • (token0 === tokenA && token1 === tokenB) || (token0 === tokenB && token1 === tokenA)
  • Pool pair matching logic

Parameters​

token0​

string

First token in pair A

token1​

string

Second token in pair A

tokenA​

string

First token in pair B

tokenB​

string

Second token in pair B

Returns​

boolean

True if both pairs represent the same token pair (in any order)

Examples​

Direct pool pair matching

import { bidirectionalTokenMatch } from '@gala-chain/launchpad-sdk';

const poolToken0 = 'GALA';
const poolToken1 = 'GUSDC';

const searchToken0 = 'GUSDC';
const searchToken1 = 'GALA';

if (bidirectionalTokenMatch(poolToken0, poolToken1, searchToken0, searchToken1)) {
// Found matching pool (order doesn't matter)
}

Finding matching DEX pool

import { bidirectionalTokenMatch } from '@gala-chain/launchpad-sdk';

const targetPool = { token0: 'GALA', token1: 'GUSDC' };
const allPools = [...];

const match = allPools.find(pool =>
bidirectionalTokenMatch(pool.token0, pool.token1, targetPool.token0, targetPool.token1)
);

Liquidity position matching

import { bidirectionalTokenMatch } from '@gala-chain/launchpad-sdk';

const position = { token0: 'GUSDC', token1: 'GALA' };
const newPoolTokens = { token0: 'GALA', token1: 'GUSDC' };

if (bidirectionalTokenMatch(position.token0, position.token1, newPoolTokens.token0, newPoolTokens.token1)) {
console.log('Position is in the same pool');
}

Since​

6.14.0