Skip to content

galleonlabs/crypto-defi-skills / packages/lp/skills/lp-monitor

lp-monitor

Verified

Evaluate an existing Uniswap v2, v3, or v4 or Aerodrome or Slipstream liquidity position. Use when the user asks whether it is in range, what it earned, how it performed versus HOLD, who controls it, whether automation is active, or whether to hold, collect, recenter, restake, reduce, or exit. Produces a current recommendation only; not transaction execution.

scripts/position.mjs

View on GitHub
#!/usr/bin/env node

import { readFile } from "node:fs/promises";

function finite(input, key, fallback) {
  const raw = input[key] ?? fallback;
  if (typeof raw !== "number" || !Number.isFinite(raw)) throw new Error(`${key} must be a finite number`);
  return raw;
}

async function main() {
  const args = process.argv.slice(2);
  if (args.includes("--help")) {
    process.stdout.write("Usage: node scripts/position.mjs --input <snapshot.json>. Use --input - for stdin. Required: tickCurrent, tickLower, tickUpper, positionAssetsUsd, holdValueUsd. Optional: edgeBufferTicks, claimableFeesUsd, claimableIncentivesUsd, realizedProceedsUsd, looseResidueUsd, costsUsd.\n");
    return;
  }
  if (args.length !== 2 || args[0] !== "--input" || !args[1]) throw new Error("expected --input <snapshot.json>");
  let source;
  if (args[1] === "-") {
    source = "";
    for await (const chunk of process.stdin) source += chunk;
  } else {
    source = await readFile(args[1], "utf8");
  }
  const input = JSON.parse(source);
  if (!input || typeof input !== "object" || Array.isArray(input)) throw new Error("input must be a JSON object");
  const tickCurrent = finite(input, "tickCurrent");
  const tickLower = finite(input, "tickLower");
  const tickUpper = finite(input, "tickUpper");
  const edgeBufferTicks = finite(input, "edgeBufferTicks", 0);
  if (![tickCurrent, tickLower, tickUpper, edgeBufferTicks].every(Number.isInteger)) throw new Error("tick values must be integers");
  if (tickLower >= tickUpper) throw new Error("tickLower must be below tickUpper");
  if (edgeBufferTicks < 0) throw new Error("edgeBufferTicks must be at least 0");
  const positionAssetsUsd = finite(input, "positionAssetsUsd");
  const holdValueUsd = finite(input, "holdValueUsd");
  const claimableFeesUsd = finite(input, "claimableFeesUsd", 0);
  const claimableIncentivesUsd = finite(input, "claimableIncentivesUsd", 0);
  const realizedProceedsUsd = finite(input, "realizedProceedsUsd", 0);
  const looseResidueUsd = finite(input, "looseResidueUsd", 0);
  const costsUsd = finite(input, "costsUsd", 0);
  if ([positionAssetsUsd, holdValueUsd, claimableFeesUsd, claimableIncentivesUsd, realizedProceedsUsd, looseResidueUsd, costsUsd].some((value) => value < 0)) {
    throw new Error("USD values must be at least 0");
  }
  if (holdValueUsd === 0) throw new Error("holdValueUsd must be greater than 0");
  const inRange = tickCurrent >= tickLower && tickCurrent < tickUpper;
  const distanceToLower = tickCurrent - tickLower;
  const distanceToUpper = tickUpper - tickCurrent;
  const lpNetValueUsd = positionAssetsUsd + claimableFeesUsd + claimableIncentivesUsd + realizedProceedsUsd + looseResidueUsd - costsUsd;
  process.stdout.write(`${JSON.stringify({
    ok: true,
    range: {
      state: tickCurrent < tickLower ? "below-range" : tickCurrent >= tickUpper ? "above-range" : "in-range",
      inRange,
      nearEdge: inRange && Math.min(distanceToLower, distanceToUpper) <= edgeBufferTicks,
      distanceToLower,
      distanceToUpper,
      percentThroughRange: inRange ? ((tickCurrent - tickLower) / (tickUpper - tickLower)) * 100 : null,
    },
    accounting: {
      lpNetValueUsd,
      holdValueUsd,
      inventoryDivergencePercent: (positionAssetsUsd / holdValueUsd - 1) * 100,
      netResultVsHoldPercent: (lpNetValueUsd / holdValueUsd - 1) * 100,
    },
  }, null, 2)}\n`);
}

function reportedError(error) {
  // JSON.parse SyntaxError messages quote the input. Node quotes a prefix;
  // Bun quotes the first identifier. Neither belongs in the result.
  if (error instanceof SyntaxError || (error instanceof Error && error.message.startsWith("JSON Parse error"))) return "invalid JSON input";
  return error instanceof Error ? error.message : String(error);
}

try {
  await main();
} catch (error) {
  process.stdout.write(`${JSON.stringify({ ok: false, error: reportedError(error) })}\n`);
  process.exitCode = 1;
}
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 196kUpdated Claude CodeCodexVerifiedInstall