Skip to main content
Glama

get_impermanent_loss

Calculate impermanent loss for a liquidity position on the Casper Network DEX. Provide account public key and pair contract to assess potential losses from price changes.

Instructions

Calculate impermanent loss for a liquidity position

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_public_keyYesAccount public key (hex)
pairYesPair contract package hash

Implementation Reference

  • The MCP tool handler for 'get_impermanent_loss' in the account tools registration.
    async ({ account_public_key, pair }) => {
      const il = await client.getImpermanentLoss(account_public_key, pair);
      return { content: [{ type: 'text' as const, text: JSON.stringify(il, null, 2) }] };
    },
  • Registration of the 'get_impermanent_loss' tool in the MCP server.
    server.tool(
      'get_impermanent_loss',
      'Calculate impermanent loss for a liquidity position',
      {
        account_public_key: z.string().describe('Account public key (hex)'),
        pair: z.string().describe('Pair contract package hash'),
      },
      async ({ account_public_key, pair }) => {
        const il = await client.getImpermanentLoss(account_public_key, pair);
        return { content: [{ type: 'text' as const, text: JSON.stringify(il, null, 2) }] };
      },
    );
  • SDK client method that calls the liquidity API to fetch impermanent loss data.
    async getImpermanentLoss(publicKey: string, pairHash: string): Promise<ImpermanentLoss> {
      const raw = await this.liquidityApi.getImpermanentLoss(publicKey, pairHash);
      return {
        pairContractPackageHash: raw.pair_contract_package_hash,
        value: raw.value,
        timestamp: raw.timestamp,
      };
    }
  • API method in LiquidityApi that performs the HTTP request to fetch impermanent loss data.
    async getImpermanentLoss(accountIdentifier: string, pairHash: string): Promise<ImpermanentLossApiResponse> {
      const response = await this.http.get<ApiResponse<ImpermanentLossApiResponse>>(
        `/accounts/${accountIdentifier}/liquidity-position-impermanent-loss`,
        { pair_contract_package_hash: pairHash }
      );
      return response.data;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/make-software/cspr-trade-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server