npm package: @kairos-loan/aleno-tb
Description: This module provides functionalities for manipulating tornado-blast-subgraph.
Author: Aleno SAS
Latest version: 1.0.17

# Aleno-tb

## Introduction

This module provides functionalities for manipulating tornado-blast-subgraph.

## Configuration

Before using this module, you need to configure the following environment variables:

- **USDB_ADDRESS**: The address for USDB token. You can set this environment variable to the desired USDB token address. If not provided, the default address `"0x4300000000000000000000000000000000000003"` will be used.
- **WETH_ADDRESS**: The address for WETH token. You can set this environment variable to the desired WETH token address. If not provided, the default address `"0x4300000000000000000000000000000000000004"` will be used.
- **THE_GRAPH_URL**: The URL for The Graph API endpoint. You can set this environment variable to the desired endpoint URL. If not provided, the default development URL `https://api.studio.thegraph.com/query/64686/tornado-blast-subgraph-mainnet/version/latest` will be used. This is a blast-mainnet rate limited endpoint for testing purpose only.

## Installation

To install and use this module in your project, follow these steps:

1. Install the module using npm:

   ```bash
   npm install @kairos-loan/aleno-tb
   ```

2. Import the module in your code:

   ```javascript
   import alenoTb from "@kairos-loan/aleno-tb";
   ```

3. Configure the environment variables as mentioned in the Configuration section above.

4. Start using the module's functionalities in your code.

## Usage

Here are some examples of how to use this module:

### Use existing queries with typing:

```javascript
import * as alenoTb from "@kairos-loan/aleno-tb";

const tokenIds = [alenoTb.WETH_ADDRESS, alenoTb.USDB_ADDRESS];
console.log(await alenoTb.getTokensInfo(tokenIds));
```

### Example of a custom query:

```javascript
import * as alenoTb from "@kairos-loan/aleno-tb";

const tokenInfoQuery = alenoTb.gql`
    query GetTokenInfo($tokenIds: [ID!]) {
        tokens(
            where: { 
                id_in: $tokenIds, 
            }, 
            first: 1000,
            orderBy: createdAtTimestamp, 
            orderDirection: desc
        ) {
          id
          symbol
          name
          decimals
        }
    }
`;
console.log(await alenoTb.executeQuery(tokenInfoQuery, { tokenIds }));
```

### Get trending tokens:

```javascript
import * as alenoTb from "@kairos-loan/aleno-tb";

console.log(await alenoTb.getTrendingTokens());
```

### Get new tokens:

```javascript
import * as alenoTb from "@kairos-loan/aleno-tb";

console.log(await alenoTb.getNewTokens());
```

### Get first 1000 results of user leader board by volume:

```javascript
import * as alenoTb from "@kairos-loan/aleno-tb";

console.log(await alenoTb.fetchUsersLeaderBoardByVolume(0, 1000));
```

### Example of setting the GemFinder:

```javascript
import * as alenoTb from "@kairos-loan/aleno-tb";

const userCache = await alenoTb.initUserCache(alenoTb.getTimestamp24HoursAgo());
const updateIntervalInSeconds = 15 * 60;
// Using pnl of 1$ in testnet for testing, this must be increased on mainnet
const pnlThreshold = 1;
let gems = await alenoTb.findGems(userCache, pnlThreshold);

const updateCacheAndFindGems = async () => {
  await alenoTb.updateUserCache(userCache, updateIntervalInSeconds);
  gems = await alenoTb.findGems(userCache, pnlThreshold);
};
setInterval(updateCacheAndFindGems, updateIntervalInSeconds * 1000);
```

### Example get pnl and swaps for a given User:

```javascript
import * as alenoTb from "@kairos-loan/aleno-tb";

const { totalPnl, processedSwaps } = await alenoTb.getPnlForUser(
  "0x00c53938f938098f82c60603386d872cbea7ceb3",
  userCache,
);
console.log(totalPnl, processedSwaps);
```

### Get User info:

```javascript
import * as alenoTb from "@kairos-loan/aleno-tb";

console.log(
  await alenoTb.getUserInfo(
    "0x001a1a6126adfd06637a75bc08ed0bc4d9f3de87",
    userCache,
  ),
);
```

### User leaderboard based on PnL:

You can implement a user leaderboard based on PnL by requesting all the users using a timestamp parameter of 0. However, this approach may be resource-intensive over time, and not all users might have a realized pnl.

Feel free to adjust the formatting or add any additional explanations as needed.