@rabby-wallet/rabby-swap 0.0.83-beta.1 → 0.0.84-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,19 @@ export type TokenPoolToken = TokenPoolLookupToken;
11
11
  */
12
12
  export declare const STABLE_TOKEN_POOL: readonly TokenPoolToken[];
13
13
  export declare const NATIVE_AND_DERIVATIVE_TOKEN_POOL: readonly TokenPoolToken[];
14
+ /**
15
+ * Returns true when both tokens are stablecoins on the same chain.
16
+ *
17
+ * Lookup is O(1) after module initialization.
18
+ */
19
+ export declare const isStableTokenPair: (tokenA: TokenPoolLookupToken | null | undefined, tokenB: TokenPoolLookupToken | null | undefined) => boolean;
20
+ /**
21
+ * Returns true when both tokens are native or derivative (LST/LRT) tokens on
22
+ * the same chain.
23
+ *
24
+ * Lookup is O(1) after module initialization.
25
+ */
26
+ export declare const isNativeAndDerivativeTokenPair: (tokenA: TokenPoolLookupToken | null | undefined, tokenB: TokenPoolLookupToken | null | undefined) => boolean;
14
27
  /**
15
28
  * Returns true when both tokens form a same-type pair in the same pool:
16
29
  * either two stablecoins, or two native/derivative tokens.
@@ -232,6 +232,38 @@ const isTokenPoolLookupToken = (token) => !!token &&
232
232
  const getTokenKey = (token) => `${token.chain.toLowerCase()}${TOKEN_KEY_SEPARATOR}${token.id.toLowerCase()}`;
233
233
  const stableTokenKeySet = new Set(STABLE_TOKEN_POOL.map(getTokenKey));
234
234
  const nativeAndDerivativeTokenKeySet = new Set(NATIVE_AND_DERIVATIVE_TOKEN_POOL.map(getTokenKey));
235
+ const getComparableTokenPairKeys = (tokenA, tokenB) => {
236
+ if (!isTokenPoolLookupToken(tokenA) || !isTokenPoolLookupToken(tokenB)) {
237
+ return null;
238
+ }
239
+ if (tokenA.chain.toLowerCase() !== tokenB.chain.toLowerCase()) {
240
+ return null;
241
+ }
242
+ return [getTokenKey(tokenA), getTokenKey(tokenB)];
243
+ };
244
+ /**
245
+ * Returns true when both tokens are stablecoins on the same chain.
246
+ *
247
+ * Lookup is O(1) after module initialization.
248
+ */
249
+ export const isStableTokenPair = (tokenA, tokenB) => {
250
+ const keys = getComparableTokenPairKeys(tokenA, tokenB);
251
+ return (!!keys &&
252
+ stableTokenKeySet.has(keys[0]) &&
253
+ stableTokenKeySet.has(keys[1]));
254
+ };
255
+ /**
256
+ * Returns true when both tokens are native or derivative (LST/LRT) tokens on
257
+ * the same chain.
258
+ *
259
+ * Lookup is O(1) after module initialization.
260
+ */
261
+ export const isNativeAndDerivativeTokenPair = (tokenA, tokenB) => {
262
+ const keys = getComparableTokenPairKeys(tokenA, tokenB);
263
+ return (!!keys &&
264
+ nativeAndDerivativeTokenKeySet.has(keys[0]) &&
265
+ nativeAndDerivativeTokenKeySet.has(keys[1]));
266
+ };
235
267
  /**
236
268
  * Returns true when both tokens form a same-type pair in the same pool:
237
269
  * either two stablecoins, or two native/derivative tokens.
@@ -239,19 +271,5 @@ const nativeAndDerivativeTokenKeySet = new Set(NATIVE_AND_DERIVATIVE_TOKEN_POOL.
239
271
  * Lookup is O(1) after module initialization. Tokens from different pools do
240
272
  * not match.
241
273
  */
242
- export const isSameTypeTokenPair = (tokenA, tokenB) => {
243
- if (!isTokenPoolLookupToken(tokenA) || !isTokenPoolLookupToken(tokenB)) {
244
- return false;
245
- }
246
- if (tokenA.chain.toLowerCase() !== tokenB.chain.toLowerCase()) {
247
- return false;
248
- }
249
- const tokenAKey = getTokenKey(tokenA);
250
- const tokenBKey = getTokenKey(tokenB);
251
- if (stableTokenKeySet.has(tokenAKey) &&
252
- stableTokenKeySet.has(tokenBKey)) {
253
- return true;
254
- }
255
- return (nativeAndDerivativeTokenKeySet.has(tokenAKey) &&
256
- nativeAndDerivativeTokenKeySet.has(tokenBKey));
257
- };
274
+ export const isSameTypeTokenPair = (tokenA, tokenB) => isStableTokenPair(tokenA, tokenB) ||
275
+ isNativeAndDerivativeTokenPair(tokenA, tokenB);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rabby-wallet/rabby-swap",
3
- "version": "0.0.83-beta.1",
3
+ "version": "0.0.84-alpha.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {