Skip to main content
Glama

write.account.deleverage

Idempotent

Sells collateral to repay debt in one atomic transaction while keeping positions active. Use this tool to reduce leverage without closing positions or using wallet tokens.

Instructions

Multi-step flash-action: sells account collateral to the debt token and repays in one atomic transaction — no wallet tokens needed. To repay from wallet tokens instead, use write.account.repay. NOTE: If you are closing a position (remove LP + swap + repay + withdraw), prefer write.account.close which batches everything atomically. Only use this tool for standalone repayment while keeping the position active. The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation — if tenderly_sim_status is 'false', do NOT broadcast the transaction.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_addressYesArcadia account address
amount_inYesCollateral amount to sell (raw units)
asset_fromYesCollateral token to sell
numeraireYesDebt token address
creditorYesLending pool address
slippageNoBasis points, 100 = 1%
chain_idNoChain ID: 8453 (Base) or 130 (Unichain)

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
afterNo
beforeNo
descriptionNo
transactionYes
tenderly_sim_urlNo
tenderly_sim_statusNo
expected_value_changeNo

Implementation Reference

  • Tool registration for "write.account.deleverage".
    server.registerTool(
      "write.account.deleverage",
      {
        annotations: {
          title: "Build Deleverage Transaction",
          readOnlyHint: false,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: true,
        },
        outputSchema: BatchedTransactionOutput,
        description:
          "Multi-step flash-action: sells account collateral to the debt token and repays in one atomic transaction — no wallet tokens needed. To repay from wallet tokens instead, use write.account.repay. NOTE: If you are closing a position (remove LP + swap + repay + withdraw), prefer write.account.close which batches everything atomically. Only use this tool for standalone repayment while keeping the position active. The returned calldata is time-sensitive — sign and broadcast within 30 seconds. If the transaction reverts due to price movement, rebuild and sign again immediately (retry at least once before giving up). Response includes tenderly_sim_url and tenderly_sim_status for pre-broadcast validation — if tenderly_sim_status is 'false', do NOT broadcast the transaction.",
        inputSchema: {
          account_address: z.string().describe("Arcadia account address"),
          amount_in: z.string().describe("Collateral amount to sell (raw units)"),
          asset_from: z.string().describe("Collateral token to sell"),
          numeraire: z.string().describe("Debt token address"),
          creditor: z.string().describe("Lending pool address"),
          slippage: z.number().optional().default(100).describe("Basis points, 100 = 1%"),
          chain_id: z.number().default(8453).describe("Chain ID: 8453 (Base) or 130 (Unichain)"),
        },
      },
      async ({ account_address, amount_in, asset_from, numeraire, creditor, slippage, chain_id }) => {
        try {
          validateAddress(account_address, "account_address");
          validateAddress(asset_from, "asset_from");
          validateAddress(numeraire, "numeraire");
          validateAddress(creditor, "creditor");
          const result = await api.getRepayCalldata({
            amount_in,
            chain_id,
            account_address,
            asset_from,
            numeraire,
            creditor,
            slippage: slippage ?? 100,
          });
    
          const res = result as Record<string, unknown>;
          if (res.tenderly_sim_status === "false") {
            const simUrl = res.tenderly_sim_url
              ? `\nTenderly simulation: ${res.tenderly_sim_url}`
              : "";
            const simError = res.tenderly_sim_error
              ? `\nRevert reason: ${res.tenderly_sim_error}`
              : "";
            return {
              content: [
                {
                  type: "text" as const,
                  text: `Error: Transaction simulation FAILED — do NOT broadcast.${simError}${simUrl}`,
                },
              ],
              isError: true,
            };
          }
    
          const response = formatBatchedResponse(res, chain_id, "Deleverage account position");
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(response, null, 2),
              },
            ],
            structuredContent: response,
          };
        } catch (err) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error: ${err instanceof Error ? err.message : String(err)}`,
              },
            ],
            isError: true,
          };
        }
      },
    );
  • The handler implementation for the "write.account.deleverage" tool, which orchestrates calls to the Arcadia API to get repay calldata.
    async ({ account_address, amount_in, asset_from, numeraire, creditor, slippage, chain_id }) => {
      try {
        validateAddress(account_address, "account_address");
        validateAddress(asset_from, "asset_from");
        validateAddress(numeraire, "numeraire");
        validateAddress(creditor, "creditor");
        const result = await api.getRepayCalldata({
          amount_in,
          chain_id,
          account_address,
          asset_from,
          numeraire,
          creditor,
          slippage: slippage ?? 100,
        });
    
        const res = result as Record<string, unknown>;
        if (res.tenderly_sim_status === "false") {
          const simUrl = res.tenderly_sim_url
            ? `\nTenderly simulation: ${res.tenderly_sim_url}`
            : "";
          const simError = res.tenderly_sim_error
            ? `\nRevert reason: ${res.tenderly_sim_error}`
            : "";
          return {
            content: [
              {
                type: "text" as const,
                text: `Error: Transaction simulation FAILED — do NOT broadcast.${simError}${simUrl}`,
              },
            ],
            isError: true,
          };
        }
    
        const response = formatBatchedResponse(res, chain_id, "Deleverage account position");
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(response, null, 2),
            },
          ],
          structuredContent: response,
        };
      } catch (err) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error: ${err instanceof Error ? err.message : String(err)}`,
            },
          ],
          isError: true,
        };
      }
    },

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/arcadia-finance/arcadia-finance-mcp-server'

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