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
| Name | Required | Description | Default |
|---|---|---|---|
| account_public_key | Yes | Account public key (hex) | |
| pair | Yes | Pair contract package hash |
Implementation Reference
- packages/mcp/src/tools/account.ts:26-29 (handler)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) }] }; }, - packages/mcp/src/tools/account.ts:19-30 (registration)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) }] }; }, ); - packages/sdk/src/client.ts:160-167 (helper)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, }; } - packages/sdk/src/api/liquidity.ts:15-21 (handler)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; }