@indigoprotocol/indigo-mcp 0.5.0 → 0.5.1

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.
package/README.md CHANGED
@@ -485,10 +485,16 @@ For any client that supports MCP over stdio, point it to the `npx @indigoprotoco
485
485
 
486
486
  | Tool | Description | Parameters |
487
487
  | ------------------------ | ------------------------------------------------------------ | ------------------------------------------- |
488
- | `get_stableswap_pool` | Get the stableswap pool state for an (iAsset, collateral) | `asset` |
489
- | `create_stableswap_order`| Build a tx to swap collateral↔iAsset via the stableswap pool | `address`, `asset`, `amount`, `minting` |
488
+ | `get_stableswap_pool` | Get the stableswap pool state for an (iAsset, collateral) | `asset`, `collateralAsset?` |
489
+ | `create_stableswap_order`| Build a tx to swap collateral↔iAsset via the stableswap pool | `address`, `asset`, `amount`, `minting`, `collateralAsset?` |
490
490
  | `cancel_stableswap_order`| Build a tx to cancel a stableswap order | `address`, `orderTxHash`, `orderOutputIndex`|
491
491
 
492
+ A stableswap pool is identified by its iAsset and its collateral, which is a stablecoin
493
+ rather than ADA. `collateralAsset` takes the token name (`USDA`, `USDM`, …) or
494
+ `<policyId>.<assetNameHex>`. It can be left out when the iAsset has a single pool; when it
495
+ has several, the error lists the choices. `get_stableswap_pool` also reports whether minting
496
+ and redemption are enabled and the minimum order amounts.
497
+
492
498
  ## Environment Variables
493
499
 
494
500
  | Variable | Required | Default | Description |
package/dist/index.js CHANGED
@@ -244031,14 +244031,6 @@ function parseStableswapPoolDatum(datum) {
244031
244031
  return Option_exports3.none;
244032
244032
  }
244033
244033
  }
244034
- function parseStableswapPoolDatumOrThrow(datum) {
244035
- return function_exports.pipe(
244036
- parseStableswapPoolDatum(datum),
244037
- Option_exports3.match(() => {
244038
- throw new Error("Expected a stableswap pool datum.");
244039
- }, function_exports.identity)
244040
- );
244041
- }
244042
244034
  function serialiseFeedInterestOracleRedeemer(redeemer) {
244043
244035
  return Data_exports3.withSchema(InterestOracleRedeemerSchema).toCBORHex(redeemer);
244044
244036
  }
@@ -248168,6 +248160,24 @@ function estimateMinOrderOutputLovelaces(lucid2, orderDatum, orderAssets) {
248168
248160
  const roundedExpectedOutputLovelaces = (expectedOutputLovelaces / 1000000n + 1n) * 1000000n;
248169
248161
  return roundedExpectedOutputLovelaces;
248170
248162
  }
248163
+ async function findAllStableswapPools(lucid2, sysParams) {
248164
+ const cdpUtxos = await lucid2.utxosAtWithUnit(
248165
+ { hash: sysParams.validatorHashes.cdpHash, type: "Script" },
248166
+ assetClassToUnit(
248167
+ fromSystemParamsAsset(sysParams.stableswapParams.cdpToken)
248168
+ )
248169
+ );
248170
+ return function_exports.pipe(
248171
+ cdpUtxos.map(
248172
+ (utxo) => function_exports.pipe(
248173
+ Option_exports3.fromNullable(utxo.datum),
248174
+ Option_exports3.flatMap(parseStableswapPoolDatum),
248175
+ Option_exports3.map((datum) => ({ utxo, datum }))
248176
+ )
248177
+ ),
248178
+ Array_exports3.compact
248179
+ );
248180
+ }
248171
248181
  async function createStableswapOrder(iasset, collateralAsset, amount, minting, poolDatum, params, lucid2, destinationAddress, destinationInlineDatum, maxExecutionFee = BASE_MAX_EXECUTION_FEE, additionalLovelaces = 0n, maxFeeRatio) {
248172
248182
  const myAddress = await lucid2.wallet().address();
248173
248183
  const pkh = paymentCredentialOf(myAddress);
@@ -248408,6 +248418,7 @@ var init_dist15 = __esm({
248408
248418
  init_dist14();
248409
248419
  init_dist11();
248410
248420
  init_dist14();
248421
+ init_es6();
248411
248422
  init_dist11();
248412
248423
  init_dist14();
248413
248424
  DEFAULT_SCHEMA_OPTIONS = {
@@ -252595,45 +252606,94 @@ var init_oracle_tools = __esm({
252595
252606
  });
252596
252607
 
252597
252608
  // src/tools/stableswap-tools.ts
252598
- async function findStableswapPool(lucid2, iasset, collateralAsset) {
252599
- const params = await getSystemParams();
252600
- const network = lucid2.config().network;
252601
- if (!network) throw new Error("Lucid network not configured");
252602
- const cdpTokenAc = fromSystemParamsAsset(params.stableswapParams.cdpToken);
252603
- const address = createScriptAddress(network, params.validatorHashes.stableswapHash);
252604
- const utxos = await lucid2.utxosAtWithUnit(address, assetClassToUnit(cdpTokenAc));
252605
- const wantHex = fromText(iasset);
252606
- for (const utxo of utxos) {
252607
- try {
252608
- const datum = parseStableswapPoolDatumOrThrow(getInlineDatumOrThrow2(utxo));
252609
- if (toHex(datum.iasset) === wantHex && isSameAssetClass(datum.collateralAsset, collateralAsset)) {
252610
- return { utxo, datum };
252611
- }
252612
- } catch {
252613
- }
252609
+ function collateralOf(datum) {
252610
+ const policyId = toHex(datum.collateralAsset.currencySymbol);
252611
+ const assetNameHex2 = toHex(datum.collateralAsset.tokenName);
252612
+ if (policyId === "") return { unit: "lovelace", name: "ADA" };
252613
+ const readable = CIP67_LABEL.test(assetNameHex2) ? assetNameHex2.slice(8) : assetNameHex2;
252614
+ return {
252615
+ unit: `${policyId}.${assetNameHex2}`,
252616
+ name: Buffer.from(readable, "hex").toString("utf8"),
252617
+ policyId,
252618
+ assetNameHex: assetNameHex2
252619
+ };
252620
+ }
252621
+ function poolLabel(pool) {
252622
+ const iasset = Buffer.from(pool.datum.iasset).toString("utf8");
252623
+ return `${iasset} / ${collateralOf(pool.datum).name}`;
252624
+ }
252625
+ function matchesCollateral(pool, wanted) {
252626
+ const collateral = collateralOf(pool.datum);
252627
+ const value3 = wanted.trim().toLowerCase();
252628
+ if (value3 === "ada" || value3 === "lovelace") return collateral.unit === "lovelace";
252629
+ return collateral.unit === value3 || collateral.unit.replace(".", "") === value3 || collateral.name.toLowerCase() === value3;
252630
+ }
252631
+ function selectStableswapPool(pools, asset, collateralAsset) {
252632
+ const assetHex = fromText(asset);
252633
+ const forAsset = pools.filter((pool) => toHex(pool.datum.iasset) === assetHex);
252634
+ if (forAsset.length === 0) {
252635
+ const existing = pools.length ? `Pools exist for: ${pools.map(poolLabel).join(", ")}.` : "No stableswap pools were found on-chain.";
252636
+ throw new Error(`No stableswap pool exists for ${asset}. ${existing}`);
252637
+ }
252638
+ const available = forAsset.map((pool) => collateralOf(pool.datum).name).join(", ");
252639
+ if (collateralAsset === void 0) {
252640
+ if (forAsset.length === 1) return forAsset[0];
252641
+ throw new Error(
252642
+ `${asset} has ${forAsset.length} stableswap pools. Pass collateralAsset as one of: ${available}.`
252643
+ );
252644
+ }
252645
+ const matching = forAsset.filter((pool) => matchesCollateral(pool, collateralAsset));
252646
+ if (matching.length === 1) return matching[0];
252647
+ if (matching.length === 0) {
252648
+ throw new Error(
252649
+ `No ${asset} stableswap pool uses collateral "${collateralAsset}". Available: ${available}.`
252650
+ );
252614
252651
  }
252615
252652
  throw new Error(
252616
- `Stableswap pool UTxO for ${iasset} / ${assetClassToUnit(collateralAsset) || "ADA"} not found`
252653
+ `"${collateralAsset}" matches ${matching.length} ${asset} stableswap pools. Pass collateralAsset as '<policyId>.<assetNameHex>' instead.`
252617
252654
  );
252618
252655
  }
252656
+ function describeStableswapPool(pool) {
252657
+ const { datum, utxo } = pool;
252658
+ return {
252659
+ txHash: utxo.txHash,
252660
+ outputIndex: utxo.outputIndex,
252661
+ datum: {
252662
+ iasset: Buffer.from(datum.iasset).toString("utf8"),
252663
+ collateralAsset: collateralOf(datum),
252664
+ collateralToIassetRatio: ratio(datum.collateralToIassetRatio),
252665
+ mintingFeeRatio: ratio(datum.mintingFeeRatio),
252666
+ redemptionFeeRatio: ratio(datum.redemptionFeeRatio),
252667
+ mintingEnabled: datum.mintingEnabled,
252668
+ redemptionEnabled: datum.redemptionEnabled,
252669
+ feeManager: datum.feeManager ? toHex(datum.feeManager) : null,
252670
+ minMintOrderAmount: datum.minMintOrderAmount.toString(),
252671
+ minRedemptionOrderAmount: datum.minRedemptionOrderAmount.toString(),
252672
+ stableswapValHash: toHex(datum.stableswapValHash)
252673
+ }
252674
+ };
252675
+ }
252676
+ async function findPool(lucid2, asset, collateralAsset) {
252677
+ const params = await getSystemParams();
252678
+ const pools = await findAllStableswapPools(lucid2, params);
252679
+ return selectStableswapPool(pools, asset, collateralAsset);
252680
+ }
252619
252681
  function registerStableswapTools(server) {
252620
252682
  server.tool(
252621
252683
  "get_stableswap_pool",
252622
- "Find the stableswap pool UTxO for an (iAsset, ADA collateral) pair and return its parsed datum",
252684
+ "Find the stableswap pool for an iAsset and return its state: collateral asset, exchange ratio, fees, whether minting and redemption are enabled, and minimum order amounts",
252623
252685
  {
252624
- asset: AssetParam.describe("iAsset name (iUSD, iBTC, iETH, or iSOL)")
252686
+ asset: AssetParam.describe("iAsset name, e.g. iUSD"),
252687
+ collateralAsset: CollateralParam
252625
252688
  },
252626
- async ({ asset }) => {
252689
+ async ({ asset, collateralAsset }) => {
252627
252690
  try {
252628
252691
  const lucid2 = await getLucid();
252629
- const pool = await findStableswapPool(lucid2, asset, ADA_COLLATERAL);
252630
- const result = {
252631
- txHash: pool.utxo.txHash,
252632
- outputIndex: pool.utxo.outputIndex,
252633
- datum: pool.datum
252634
- };
252692
+ const pool = await findPool(lucid2, asset, collateralAsset);
252635
252693
  return {
252636
- content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
252694
+ content: [
252695
+ { type: "text", text: JSON.stringify(describeStableswapPool(pool), null, 2) }
252696
+ ]
252637
252697
  };
252638
252698
  } catch (error2) {
252639
252699
  return {
@@ -252650,25 +252710,34 @@ function registerStableswapTools(server) {
252650
252710
  );
252651
252711
  server.tool(
252652
252712
  "create_stableswap_order",
252653
- "Submit a stableswap order: swap collateral for iAsset (minting=true) or iAsset for collateral (minting=false). Returns an unsigned transaction (CBOR hex) for client-side signing.",
252713
+ "Submit a stableswap order: swap the pool collateral for iAsset (minting=true) or iAsset for the pool collateral (minting=false). Returns an unsigned transaction (CBOR hex) for client-side signing. See get_stableswap_pool for the collateral asset and minimum order amounts.",
252654
252714
  {
252655
252715
  address: external_exports.string().describe("User Cardano bech32 address"),
252656
- asset: AssetParam.describe("iAsset name (iUSD, iBTC, iETH, or iSOL)"),
252657
- amount: external_exports.string().describe("Amount in smallest unit to swap"),
252716
+ asset: AssetParam.describe("iAsset name, e.g. iUSD"),
252717
+ amount: external_exports.string().describe(
252718
+ "Amount to swap in the smallest unit of the asset being paid in: the collateral when minting, the iAsset when redeeming"
252719
+ ),
252658
252720
  minting: external_exports.boolean().describe(
252659
252721
  "true = collateral \u2192 iAsset (mint direction); false = iAsset \u2192 collateral (redeem direction)"
252660
- )
252722
+ ),
252723
+ collateralAsset: CollateralParam
252661
252724
  },
252662
- async ({ address, asset, amount, minting }) => {
252725
+ async ({ address, asset, amount, minting, collateralAsset }) => {
252663
252726
  try {
252664
252727
  const result = await buildUnsignedTx(
252665
252728
  address,
252666
252729
  async (lucid2) => {
252667
252730
  const params = await getSystemParams();
252668
- const pool = await findStableswapPool(lucid2, asset, ADA_COLLATERAL);
252731
+ const pool = await findPool(lucid2, asset, collateralAsset);
252732
+ if (minting && !pool.datum.mintingEnabled) {
252733
+ throw new Error(`Minting is currently disabled for the ${poolLabel(pool)} pool`);
252734
+ }
252735
+ if (!minting && !pool.datum.redemptionEnabled) {
252736
+ throw new Error(`Redemption is currently disabled for the ${poolLabel(pool)} pool`);
252737
+ }
252669
252738
  return createStableswapOrder(
252670
252739
  asset,
252671
- ADA_COLLATERAL,
252740
+ pool.datum.collateralAsset,
252672
252741
  BigInt(amount),
252673
252742
  minting,
252674
252743
  pool.datum,
@@ -252679,7 +252748,13 @@ function registerStableswapTools(server) {
252679
252748
  {
252680
252749
  type: "create_stableswap_order",
252681
252750
  description: `${minting ? "Mint" : "Redeem"} ${asset} stableswap order for ${amount} units`,
252682
- inputs: { address, asset, amount, minting: String(minting) }
252751
+ inputs: {
252752
+ address,
252753
+ asset,
252754
+ amount,
252755
+ minting: String(minting),
252756
+ ...collateralAsset ? { collateralAsset } : {}
252757
+ }
252683
252758
  }
252684
252759
  );
252685
252760
  return {
@@ -252742,18 +252817,25 @@ function registerStableswapTools(server) {
252742
252817
  }
252743
252818
  );
252744
252819
  }
252820
+ var CollateralParam, CIP67_LABEL, ratio;
252745
252821
  var init_stableswap_tools = __esm({
252746
252822
  "src/tools/stableswap-tools.ts"() {
252747
252823
  "use strict";
252748
252824
  init_zod();
252749
252825
  init_dist11();
252750
252826
  init_dist15();
252751
- init_dist14();
252752
252827
  init_lucid_provider();
252753
252828
  init_tx_builder();
252754
252829
  init_sdk_config();
252755
- init_v3_finders();
252756
252830
  init_validators();
252831
+ CollateralParam = external_exports.string().optional().describe(
252832
+ "Collateral asset of the pool: its token name (e.g. USDA), '<policyId>.<assetNameHex>', or ADA. Optional when the iAsset has a single stableswap pool, which is then used."
252833
+ );
252834
+ CIP67_LABEL = /^0[0-9a-f]{6}0/;
252835
+ ratio = (r2) => ({
252836
+ numerator: r2.numerator.toString(),
252837
+ denominator: r2.denominator.toString()
252838
+ });
252757
252839
  }
252758
252840
  });
252759
252841
 
@@ -264597,7 +264679,7 @@ var init_package = __esm({
264597
264679
  "package.json"() {
264598
264680
  package_default2 = {
264599
264681
  name: "@indigoprotocol/indigo-mcp",
264600
- version: "0.5.0",
264682
+ version: "0.5.1",
264601
264683
  type: "module",
264602
264684
  description: "MCP server for Indigo Protocol",
264603
264685
  main: "dist/index.js",
@@ -1,3 +1,52 @@
1
1
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import type { UTxO } from '@lucid-evolution/lucid';
3
+ import type { StableswapPoolContent } from '@indigo-labs/indigo-sdk';
4
+ export type StableswapPool = {
5
+ utxo: UTxO;
6
+ datum: StableswapPoolContent;
7
+ };
8
+ /**
9
+ * Pick the stableswap pool for an iAsset from the pools found on-chain.
10
+ *
11
+ * A pool is identified by its (iAsset, collateral) pair, and the collateral is
12
+ * a stablecoin, not ADA. With one pool for the iAsset the collateral can be
13
+ * left out; with several it has to be named.
14
+ */
15
+ export declare function selectStableswapPool(pools: StableswapPool[], asset: string, collateralAsset?: string): StableswapPool;
16
+ /**
17
+ * A pool in JSON-safe form. The datum holds bigints and byte arrays, which
18
+ * `JSON.stringify` cannot serialise (bigint) or renders as index maps (bytes).
19
+ */
20
+ export declare function describeStableswapPool(pool: StableswapPool): {
21
+ txHash: string;
22
+ outputIndex: number;
23
+ datum: {
24
+ iasset: string;
25
+ collateralAsset: {
26
+ unit: string;
27
+ name: string;
28
+ policyId?: string;
29
+ assetNameHex?: string;
30
+ };
31
+ collateralToIassetRatio: {
32
+ numerator: string;
33
+ denominator: string;
34
+ };
35
+ mintingFeeRatio: {
36
+ numerator: string;
37
+ denominator: string;
38
+ };
39
+ redemptionFeeRatio: {
40
+ numerator: string;
41
+ denominator: string;
42
+ };
43
+ mintingEnabled: boolean;
44
+ redemptionEnabled: boolean;
45
+ feeManager: string | null;
46
+ minMintOrderAmount: string;
47
+ minRedemptionOrderAmount: string;
48
+ stableswapValHash: string;
49
+ };
50
+ };
2
51
  export declare function registerStableswapTools(server: McpServer): void;
3
52
  //# sourceMappingURL=stableswap-tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stableswap-tools.d.ts","sourceRoot":"","sources":["../../src/tools/stableswap-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AA6DzE,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAsI/D"}
1
+ {"version":3,"file":"stableswap-tools.d.ts","sourceRoot":"","sources":["../../src/tools/stableswap-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,OAAO,KAAK,EAAkB,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAWrE,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAiD1E;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,EAAE,EACvB,KAAK,EAAE,MAAM,EACb,eAAe,CAAC,EAAE,MAAM,GACvB,cAAc,CA+BhB;AAOD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc;;;;;;kBAtFnD,MAAM;kBACN,MAAM;uBACD,MAAM;2BACF,MAAM;;;;;;;;;;;;;;;;;;;;;EAsGtB;AAmBD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CAqJ/D"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indigoprotocol/indigo-mcp",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "description": "MCP server for Indigo Protocol",
6
6
  "main": "dist/index.js",