Skip to content

refactor(setups): create setups module#308

Draft
robert-zaremba wants to merge 26 commits intomasterfrom
robert/setups
Draft

refactor(setups): create setups module#308
robert-zaremba wants to merge 26 commits intomasterfrom
robert/setups

Conversation

@robert-zaremba
Copy link
Contributor

@robert-zaremba robert-zaremba commented Jan 19, 2026

Summary by Sourcery

Introduce a dedicated setups module to centralize configuration for NBTC and BTC light client setups across Sui networks.

New Features:

  • Add a setups module defining shared NBTC and BTC light client configuration types and a combined Setup model for Sui and Bitcoin networks.
  • Introduce an initial staging setups registry for organizing setups by organization.

Enhancements:

  • Move and expand NBTC configuration typing out of the nsui module into the new setups module, aligning it with the setups table schema.

Signed-off-by: Robert Zaremba <robert@zaremba.ch>
@robert-zaremba robert-zaremba self-assigned this Jan 19, 2026
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 19, 2026

Reviewer's Guide

Refactors configuration types into a new setups module that models on-chain setup records and prepares environment-specific setups, while simplifying nsui exports.

Class diagram for new setups module configuration types

classDiagram
    class NbtcCfg {
        +string nbtc_pkg
        +string nbtc_contract
        +string sui_fallback_addr
    }

    class BtcLCCfg {
        +string lc_pkg
        +string lc_contract
    }

    class Setup {
        +number id
        +BtcNet btc_network
        +SuiNet sui_network
        +number is_active
    }

    class orgSetups {
        +Record~string, Setup[]~ setups
    }

    Setup --|> NbtcCfg
    Setup --|> BtcLCCfg

    orgSetups --> Setup
Loading

File-Level Changes

Change Details Files
Introduce a dedicated setups module that defines configuration types aligned with the setups table and relocates NbtcCfg from nsui into this module.
  • Remove the NbtcCfg interface from the Sui utilities file, keeping only the NbtcPkg type there with a TODO to migrate to setup_id in the future.
  • Create a new setups module that defines NbtcCfg and BtcLCCfg using snake_case fields that match persistent storage (e.g., SQLite) and on-chain structures.
  • Define a composite Setup type that extends both NbtcCfg and BtcLCCfg, adds identifiers and network metadata, and documents its required sync with the setups table.
  • Add an initial staging setup array and export an orgSetups map keyed by organization/environment, as a placeholder for future fully-defined setups.
  • Stub out a validateOrSetups helper intended to ensure unique setup IDs and prevent mixing incompatible Sui/BTC networks.
packages/lib/src/nsui.ts
packages/lib/src/setups.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Copy link
Contributor

@Rcc999 Rcc999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left comment

const storage = new D1Storage(env.DB);
const activeNetworks = await storage.getActiveNetworks();
const storage = new D1Storage(env.DB, env.SETUP_ENV);
const activeNetworks = storage.getSuiNetworks();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did we remove the await here? Since the method is still async and returns Promise<SuiNet[]>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because it's stored in TS files, not in DB. We had a few discussions about it during our planning.

Copy link
Contributor

@Rcc999 Rcc999 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more comments


getSuiNetworks(): SuiNet[] {
const l: SuiNet[] = [];
for (const [_, s] of this.activeSetups) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.activeSetups is an array why are iterating as keu value pairs?

Copy link
Contributor Author

@robert-zaremba robert-zaremba Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was a mapping in my previous iteration, I didn't fix all bugs yet.

Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Copy link
Contributor

@sczembor sczembor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small review

lc_contract: string;
}

// This types uses only SQLite types and all structures form that types.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought we removed the table

}

// TODO: should be by setup_id
async getBroadcastedRedeemTxIds(btcNet: string): Promise<string[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should stay by netowrk, we can have 3 setups all pointing to the same bitcoin network

Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Signed-off-by: Robert Zaremba <robert@zaremba.ch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants