Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@cosmjs/stargate": "0.30.1",
"@dotenvx/dotenvx": "^1.6.4",
"@lit-protocol/accs-schemas": "^0.0.36",
"@lit-protocol/contracts": "^0.0.74",
"@lit-protocol/contracts": "0.0.74",
"@lit-protocol/lit-status-sdk": "^0.1.8",
"@metamask/eth-sig-util": "5.0.2",
"@mysten/sui.js": "^0.37.1",
Expand Down
20 changes: 18 additions & 2 deletions packages/constants/src/lib/constants/mappers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import depd from 'depd';

import { datilDev, datilTest, datil } from '@lit-protocol/contracts';

import { LIT_NETWORK_VALUES } from './constants';

// Legacy root import that drags every network/ABI blob into bundles; keep commented as a warning.
// import { datil, datilDev, datilTest } from '@lit-protocol/contracts';

// @ts-ignore -- TypeScript can't resolve the subpath because this package compiles to CJS, but runtime bundlers can.
import { datil as datilContext } from '@lit-protocol/contracts/prod/datil.js';
// @ts-ignore -- see note above.
import { datilDev as datilDevContext } from '@lit-protocol/contracts/prod/datil-dev.js';
// @ts-ignore -- see note above.
import { datilTest as datilTestContext } from '@lit-protocol/contracts/prod/datil-test.js';

type DatilContext = typeof datilContext;
type DatilDevContext = typeof datilDevContext;
type DatilTestContext = typeof datilTestContext;

const datil: DatilContext = datilContext;
const datilDev: DatilDevContext = datilDevContext;
const datilTest: DatilTestContext = datilTestContext;

Comment on lines +9 to +22
Copy link

Copilot AI Oct 18, 2025

Choose a reason for hiding this comment

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

These re-assignments from imported contexts to new constants appear unnecessary. The imports could be renamed directly using import { datil as datilContext } from ... and then used as datilContext throughout the code, or imported as datil directly to maintain the existing variable names. The current approach adds extra indirection without clear benefit.

Suggested change
import { datil as datilContext } from '@lit-protocol/contracts/prod/datil.js';
// @ts-ignore -- see note above.
import { datilDev as datilDevContext } from '@lit-protocol/contracts/prod/datil-dev.js';
// @ts-ignore -- see note above.
import { datilTest as datilTestContext } from '@lit-protocol/contracts/prod/datil-test.js';
type DatilContext = typeof datilContext;
type DatilDevContext = typeof datilDevContext;
type DatilTestContext = typeof datilTestContext;
const datil: DatilContext = datilContext;
const datilDev: DatilDevContext = datilDevContext;
const datilTest: DatilTestContext = datilTestContext;
import { datil } from '@lit-protocol/contracts/prod/datil.js';
// @ts-ignore -- see note above.
import { datilDev } from '@lit-protocol/contracts/prod/datil-dev.js';
// @ts-ignore -- see note above.
import { datilTest } from '@lit-protocol/contracts/prod/datil-test.js';

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

it seems like you prob need the typedefs here, and copilot is wrong?

const deprecated = depd('lit-js-sdk:constants:mappers');

/**
Expand Down
150 changes: 150 additions & 0 deletions verify-contracts-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
#!/usr/bin/env bash

# Quick sanity check for consumers of @lit-protocol/constants and contracts-sdk.
# We spin up two tiny entry points, bundle them with esbuild, and dump which
# @lit-protocol/contracts artifacts actually end up in the output. That makes it
# easy to see whether only the intended network blobs are being shipped.

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$SCRIPT_DIR"
BUNDLE_DIR="$ROOT_DIR/tmp/bundle-test"
ESBUILD="$ROOT_DIR/node_modules/.bin/esbuild"

if [[ ! -x "$ESBUILD" ]]; then
echo "esbuild not found at $ESBUILD; run yarn install first." >&2
exit 1
fi

mkdir -p "$BUNDLE_DIR"

# Modules that are Node-only; when bundling for browsers we treat them as
# externals so esbuild doesn't error on builtins like `crypto`.
BROWSER_EXTERNALS=(
assert buffer child_process crypto fs http https module net os path stream
timers tls tty url util zlib
)
BROWSER_EXTERNAL_ARGS=()
for mod in "${BROWSER_EXTERNALS[@]}"; do
BROWSER_EXTERNAL_ARGS+=(--external:"$mod")
done

# Generate the constants entry: loads NETWORK_CONTEXT_BY_NETWORK so the mapper
# import path is exercised the same way a consuming app would.
cat >"$BUNDLE_DIR/constants-entry.js" <<'JS'
const { NETWORK_CONTEXT_BY_NETWORK } = require('@lit-protocol/constants');
if (!NETWORK_CONTEXT_BY_NETWORK?.datil) {
throw new Error('datil context missing');
}
console.log('datil contracts count:', NETWORK_CONTEXT_BY_NETWORK.datil.data.length);
JS

# Generate the contracts SDK entry: touches LitContracts to mimic a typical SDK
# consumer without pulling in unrelated code.
cat >"$BUNDLE_DIR/contracts-sdk-entry.js" <<'JS'
const { LitContracts } = require('@lit-protocol/contracts-sdk');
if (typeof LitContracts !== 'function') {
throw new Error('LitContracts constructor not found');
}
console.log('LitContracts ready');
JS

# Bundle both entries for browser + node targets so we catch regressions in
# either environment.
echo "⭐️ [Browser] Bundling @lit-protocol/constants mapper..."
"$ESBUILD" "$BUNDLE_DIR/constants-entry.js" \
--bundle \
--platform=browser \
--format=esm \
--outfile="$BUNDLE_DIR/constants-browser-bundle.js" \
--metafile="$BUNDLE_DIR/constants-browser-meta.json" \
"${BROWSER_EXTERNAL_ARGS[@]}" \
--log-level=info >/dev/null

echo "⭐️ [CJS] Bundling @lit-protocol/constants mapper..."
"$ESBUILD" "$BUNDLE_DIR/constants-entry.js" \
--bundle \
--platform=node \
--format=cjs \
--outfile="$BUNDLE_DIR/constants-node-bundle.cjs" \
--metafile="$BUNDLE_DIR/constants-node-meta.json" \
--log-level=info >/dev/null

echo "⭐️ [Browser] Bundling @lit-protocol/contracts-sdk..."
"$ESBUILD" "$BUNDLE_DIR/contracts-sdk-entry.js" \
--bundle \
--platform=browser \
--format=esm \
--outfile="$BUNDLE_DIR/contracts-sdk-browser-bundle.js" \
--metafile="$BUNDLE_DIR/contracts-sdk-browser-meta.json" \
"${BROWSER_EXTERNAL_ARGS[@]}" \
--log-level=info >/dev/null

echo "⭐️ [CJS] Bundling @lit-protocol/contracts-sdk..."
"$ESBUILD" "$BUNDLE_DIR/contracts-sdk-entry.js" \
--bundle \
--platform=node \
--format=cjs \
--outfile="$BUNDLE_DIR/contracts-sdk-node-bundle.cjs" \
--metafile="$BUNDLE_DIR/contracts-sdk-node-meta.json" \
--log-level=info >/dev/null

# Pretty-print the relevant portion of esbuild's metafile so it's obvious which
# contract blobs made it into the bundle and their combined size.
summarise_meta () {
local label="$1"
local meta_path="$2"
local indent="${3:-}"
echo ""
echo "${indent}${label}"
echo "${indent} (Every line below lists a bundled @lit-protocol/contracts file and its raw size)"
META_PATH="$meta_path" INDENT="$indent" node - <<'NODE'
const path = require('path');
const metaPath = process.env.META_PATH;
const meta = require(metaPath);
const indent = process.env.INDENT || '';
const entries = Object.entries(meta.inputs)
.filter(([p]) => p.includes(path.join('@lit-protocol', 'contracts')));
if (entries.length === 0) {
console.log(`${indent} <no @lit-protocol/contracts files detected>`);
process.exit(0);
}
let total = 0;
for (const [file, info] of entries) {
total += info.bytes;
console.log(`${indent} ${file} -> ${(info.bytes / 1024).toFixed(2)} KiB`);
}
console.log(`${indent} Total -> ${(total / 1024 / 1024).toFixed(3)} MiB`);
NODE
echo "${indent} (Total reflects the sum of those files before compression/minification)"
}

summarise_package () {
local package_label="$1"
local browser_meta="$2"
local node_meta="$3"

echo ""
echo "⭐️ ${package_label} bundles:"
summarise_meta "Browser includes:" "$browser_meta" " "
summarise_meta "Node includes:" "$node_meta" " "
}

summarise_package "@lit-protocol/constants" \
"$BUNDLE_DIR/constants-browser-meta.json" \
"$BUNDLE_DIR/constants-node-meta.json"

summarise_package "@lit-protocol/contracts-sdk" \
"$BUNDLE_DIR/contracts-sdk-browser-meta.json" \
"$BUNDLE_DIR/contracts-sdk-node-meta.json"

echo ""
echo "Artifacts written to $BUNDLE_DIR"