npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@calc_fi/strategy-builder

v0.1.30

Published

Type-safe strategy builder for CALC

Readme

CALC SDK

Type-safe strategy configuration builder for CALC. Build and validate Node[] graphs from a small DSL.

What is a CALC strategy?

  • A strategy is a directed graph of nodes executed by CALC contracts.
  • Nodes are either Conditions (branch on state/time) or Actions (do work).
  • Edges define flow: conditions branch to on_success/on_failure; actions have a linear next.
  • This SDK helps you construct valid strategy graphs (Node[]) to submit with your own on-chain client.

Example: DCA (schedule → swap → distribute)

import { strategy, actions, conditions } from "@calc_fi/strategy-builder";

strategy("DCA RUNE→USDC")
  .when(
    conditions.schedule({
      cadence: { blocks: { interval: 10 } },
    })
  )
  .then(
    actions.swap({
      swap_amount: { amount: "1000000", denom: "rune" },
      minimum_receive_amount: { amount: "950000", denom: "eth-usdc" },
      routes: [{ fin: { pair_address: "fin1...pair" } }],
    })
  )
  .then(
    actions.distribute({
      denoms: ["uusdc"],
      destinations: [
        { recipient: { bank: { address: "cosmos1..." } }, shares: "10000" },
      ],
    })
  )
  .build();

Strategy Builder DSL

  • strategy(label)
    • when(condition) — add a schedule condition (entry or chained)
    • if(condition) — add any non-schedule condition
    • then(step) — Action or Condition
      • from a condition: sets on_success
      • from an action: sets next
    • else(step) — attaches on_failure to the most recent condition
    • update(index, step) — replace node payload at index (Action→Action, Condition→Condition)
    • validate() — Kahn’s algorithm for cycles; enforces single entry and full connectivity
    • build() — validates and returns a strategy: { label, nodes, owner?, source? }
  • StrategyBuilder.from({ label, nodes, ... }) — edit/validate an existing graph

Actions (what you can do)

Swap

Market swap via one or more routes (FIN, Thorchain).

actions.swap({
  swap_amount: { amount: "1000000", denom: "uatom" },
  minimum_receive_amount: { amount: "950000", denom: "uusdc" },
  routes: [{ fin: { pair_address: "fin1...pair" } }],
});

Limit Orders

Place/refresh a limit order on FIN at a either a fixed or dynamic price.

actions.limit_order({
  pair_address: "fin1...pair",
  side: "base",
  strategy: { fixed: "10.00" },
  bid_denom: "uusdc",
  bid_amount: "10000000",
});

Distribute

Distribute funds to multiple recipients.

actions.distribute({
  denoms: ["uusdc"],
  destinations: [
    { recipient: { bank: { address: "cosmos1..." } }, shares: "10000" },
  ],
});

Conditions (if/when to act)

Schedule

Repeatedly trigger strategy execution on a time, block, or cron schedule.

conditions.schedule({
  cadence: { blocks: { interval: 10 } },
});

Timestamp elapsed

True after a specific UNIX timestamp (seconds).

conditions.timestampElapsed("1712345678");

Blocks completed

True after N blocks.

conditions.blocksCompleted(100);

Can swap

Feasibility check for a prospective swap action.

conditions.canSwap({
  swap_amount: { amount: "1000000", denom: "uatom" },
  minimum_receive_amount: { amount: "950000", denom: "uusdc" },
  routes: [{ fin: { pair_address: "fin1...pair" } }],
});

Balance available

True if an address (or the strategy, if omitted) has at least the specified amount.

conditions.balanceAvailable({
  address: "cosmos1...",
  amount: { amount: "1000000", denom: "uusdc" },
});

Strategy status

True if a strategy’s status matches.

conditions.strategyStatus({
  contract_address: "cosmos1strategy...",
  manager_contract: "cosmos1manager...",
  status: "active",
});

Oracle price

True if an asset price is above/below a threshold.

conditions.oraclePrice({
  asset: "ATOM/USDC",
  direction: "below",
  price: "10.00",
});

FIN limit order filled

True if a FIN order at price/side has filled (optionally for a specific owner).

conditions.finLimitOrderFilled({
  pair_address: "fin1...pair",
  side: "base",
  price: "10.00",
});

Asset value ratio

True if an asset ratio is within tolerance from a given oracle.

conditions.assetValueRatio({
  numerator: "ATOM",
  denominator: "USDC",
  oracle: "thorchain",
  ratio: "10.00",
  tolerance: "0.50",
});

Notes

  • Types are defined in calc.d.ts and published with the package.
  • On-chain numeric types are strings:
    • Uint128: non-negative integer string.
    • Decimal: fixed-point with up to 18 fractional digits.