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
7 changes: 7 additions & 0 deletions .changeset/replace-bigints-in-sdk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ensnode/ensnode-sdk": minor
"ensapi": patch
"ensindexer": patch
---

Added `replaceBigInts` (sourced from `@ponder/utils`) and `toJson` helpers to `@ensnode/ensnode-sdk`. `toJson` now takes an options object (`{ pretty?: boolean }`) with `pretty` defaulting to `false` — pass `{ pretty: true }` for indented output. Migrated all in-repo call sites and dropped the `@ponder/utils` dependency from `ensapi`.
1 change: 0 additions & 1 deletion apps/ensadmin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@graphiql/toolkit": "0.11.3",
"@icons-pack/react-simple-icons": "^13.7.0",
"@namehash/namehash-ui": "workspace:*",
"@ponder/utils": "catalog:",
"@radix-ui/react-avatar": "^1.1.3",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-collapsible": "^1.1.3",
Expand Down
1 change: 0 additions & 1 deletion apps/ensapi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"@opentelemetry/sdk-trace-node": "^2.0.1",
"@opentelemetry/semantic-conventions": "^1.34.0",
"@ponder/client": "catalog:",
"@ponder/utils": "catalog:",
"@pothos/core": "^4.10.0",
"@pothos/plugin-dataloader": "^4.4.3",
"@pothos/plugin-relay": "^4.6.2",
Expand Down
10 changes: 5 additions & 5 deletions apps/ensapi/src/handlers/api/resolution/resolution-api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { replaceBigInts } from "@ponder/utils";
import type { Duration } from "enssdk";

import type {
ResolvePrimaryNameResponse,
ResolvePrimaryNamesResponse,
ResolveRecordsResponse,
import {
type ResolvePrimaryNameResponse,
type ResolvePrimaryNamesResponse,
type ResolveRecordsResponse,
replaceBigInts,
} from "@ensnode/ensnode-sdk";

import { createApp } from "@/lib/hono-factory";
Expand Down
8 changes: 4 additions & 4 deletions apps/ensapi/src/lib/resolution/forward-resolution.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import config from "@/config";

import { trace } from "@opentelemetry/api";
import { replaceBigInts } from "@ponder/utils";
import {
type AccountId,
asInterpretedName,
Expand All @@ -23,6 +22,7 @@ import {
PluginName,
type ResolverRecordsSelection,
TraceableENSProtocol,
toJson,
} from "@ensnode/ensnode-sdk";
import {
isBridgedResolver,
Expand Down Expand Up @@ -119,7 +119,7 @@ async function _resolveForward<SELECTION extends ResolverRecordsSelection>(
} = options;

// `selection` may contain bigints (e.g. `abi: ContentType`); stringify safely for tracing.
const selectionString = JSON.stringify(replaceBigInts(selection, String));
const selectionString = toJson(selection);

// trace for external consumers
return withEnsProtocolStep(
Expand Down Expand Up @@ -164,7 +164,7 @@ async function _resolveForward<SELECTION extends ResolverRecordsSelection>(

// construct the set of resolve() operations indicated by node/selection
let operations = makeOperations(node, selection);
span.setAttribute("operations", JSON.stringify(replaceBigInts(operations, String)));
span.setAttribute("operations", toJson(operations));

// if no operations were generated, this was an empty selection; give them what they asked for
if (operations.length === 0) return makeRecordsResponse<SELECTION>(operations);
Expand Down Expand Up @@ -354,7 +354,7 @@ async function _resolveForward<SELECTION extends ResolverRecordsSelection>(
// Invariant: all operations must be resolved
if (!operations.every(isOperationResolved)) {
throw new Error(
`Invariant(forward-resolution): Not all operations were resolved at the end of resolution!\n${JSON.stringify(replaceBigInts(operations, String))}`,
`Invariant(forward-resolution): Not all operations were resolved at the end of resolution!\n${toJson(operations, { pretty: true })}`,
);
}

Expand Down
4 changes: 2 additions & 2 deletions apps/ensindexer/src/lib/heal-addr-reverse-subname-label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import config from "@/config";
import type { LabelHash, LiteralLabel, NormalizedAddress } from "enssdk";

import { getENSRootChainId } from "@ensnode/datasources";
import { toJson } from "@ensnode/ensnode-sdk";

import type { IndexingEngineContext } from "@/lib/indexing-engines/ponder";
import { toJson } from "@/lib/json-stringify-with-bigints";
import { maybeHealLabelByAddrReverseSubname } from "@/lib/maybe-heal-label-by-addr-reverse-subname";
import type { EventWithArgs } from "@/lib/ponder-helpers";
import {
Expand Down Expand Up @@ -101,6 +101,6 @@ export async function healAddrReverseSubnameLabel(

// Invariant: by this point, we should have healed all subnames of addr.reverse
throw new Error(
`Invariant(healAddrReverseSubnameLabel): Unable to heal the label for subname of addr.reverse with labelHash '${labelHash}'. Event:\n${toJson(event)}`,
`Invariant(healAddrReverseSubnameLabel): Unable to heal the label for subname of addr.reverse with labelHash '${labelHash}'. Event:\n${toJson(event, { pretty: true })}`,
);
}
7 changes: 0 additions & 7 deletions apps/ensindexer/src/lib/json-stringify-with-bigints.ts

This file was deleted.

5 changes: 2 additions & 3 deletions apps/ensindexer/src/lib/managed-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ import {
accountIdEqual,
getDatasourceContract,
maybeGetDatasourceContract,
toJson,
} from "@ensnode/ensnode-sdk";

import { toJson } from "@/lib/json-stringify-with-bigints";

/**
* Many contracts within the ENSv1 Ecosystem are relative to a parent Name. For example,
* the .eth BaseRegistrar (and RegistrarControllers) manage direct subnames of .eth. As such, they
Expand Down Expand Up @@ -162,7 +161,7 @@ export const getManagedName = (contract: AccountId): { name: InterpretedName; no
}

throw new Error(
`The following contract ${toJson(contract)} does not have a configured Managed Name. See apps/ensindexer/src/lib/managed-names.ts.`,
`The following contract ${toJson(contract, { pretty: true })} does not have a configured Managed Name. See apps/ensindexer/src/lib/managed-names.ts.`,
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
} from "enssdk";
import { isAddressEqual, zeroAddress } from "viem";

import { interpretAddress, isRegistrationFullyExpired, PluginName } from "@ensnode/ensnode-sdk";
import {
interpretAddress,
isRegistrationFullyExpired,
PluginName,
toJson,
} from "@ensnode/ensnode-sdk";

import { ensureAccount } from "@/lib/ensv2/account-db-helpers";
import { materializeENSv1DomainEffectiveOwner } from "@/lib/ensv2/domain-db-helpers";
Expand All @@ -25,7 +30,6 @@ import {
ensIndexerSchema,
type IndexingEngineContext,
} from "@/lib/indexing-engines/ponder";
import { toJson } from "@/lib/json-stringify-with-bigints";
import { getManagedName } from "@/lib/managed-names";
import { namespaceContract } from "@/lib/plugin-helpers";
import type { EventWithArgs } from "@/lib/ponder-helpers";
Expand Down Expand Up @@ -120,7 +124,7 @@ export default function () {
// Invariant: If there is an existing Registration, it must be fully expired.
if (registration && !isFullyExpired) {
throw new Error(
`Invariant(BaseRegistrar:NameRegistered): Existing unexpired registration found in NameRegistered, expected none or expired.\n${toJson(registration)}`,
`Invariant(BaseRegistrar:NameRegistered): Existing unexpired registration found in NameRegistered, expected none or expired.\n${toJson(registration, { pretty: true })}`,
);
}

Expand Down Expand Up @@ -184,6 +188,7 @@ export default function () {
node,
domainId,
},
{ pretty: true },
)}`,
);
}
Expand All @@ -193,6 +198,7 @@ export default function () {
throw new Error(
`Invariant(BaseRegistrar:NameRenewed): NameRenewed emitted for a non-BaseRegistrar registration:\n${toJson(
{ labelHash, managedNode, node, domainId, registration },
{ pretty: true },
)}`,
);
}
Expand All @@ -202,6 +208,7 @@ export default function () {
throw new Error(
`Invariant(BaseRegistrar:NameRenewed): NameRenewed emitted for a BaseRegistrar registration that has a null expiry:\n${toJson(
{ labelHash, managedNode, node, domainId, registration },
{ pretty: true },
)}`,
);
}
Expand All @@ -219,6 +226,7 @@ export default function () {
registration,
timestamp: event.block.timestamp,
},
{ pretty: true },
)}`,
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
isRegistrationFullyExpired,
isRegistrationInGracePeriod,
PluginName,
toJson,
} from "@ensnode/ensnode-sdk";

import { ensureAccount } from "@/lib/ensv2/account-db-helpers";
Expand All @@ -38,7 +39,6 @@ import {
ensIndexerSchema,
type IndexingEngineContext,
} from "@/lib/indexing-engines/ponder";
import { toJson } from "@/lib/json-stringify-with-bigints";
import { logger } from "@/lib/logger";
import { getManagedName } from "@/lib/managed-names";
import { namespaceContract } from "@/lib/plugin-helpers";
Expand Down Expand Up @@ -128,15 +128,15 @@ export default function () {
// Invariant: must have Registration
if (!registration) {
throw new Error(
`Invariant(NameWrapper:Transfer): Registration expected:\n${toJson(registration)}`,
`Invariant(NameWrapper:Transfer): Registration expected:\n${toJson(registration, { pretty: true })}`,
);
}

// Invariant: Expired Registrations are non-transferrable if PCC is set
const cannotTransferWhileExpired = registration.fuses && isPccFuseSet(registration.fuses);
if (isExpired && cannotTransferWhileExpired) {
throw new Error(
`Invariant(NameWrapper:Transfer): Transfer of expired Registration with PARENT_CANNOT_CONTROL set:\n${toJson(registration)} ${JSON.stringify({ isPccFuseSet: isPccFuseSet(registration.fuses ?? 0) })}`,
`Invariant(NameWrapper:Transfer): Transfer of expired Registration with PARENT_CANNOT_CONTROL set:\n${toJson(registration, { pretty: true })} ${JSON.stringify({ isPccFuseSet: isPccFuseSet(registration.fuses ?? 0) })}`,
);
}

Expand Down Expand Up @@ -203,21 +203,21 @@ export default function () {
// Invariant: Cannot wrap grace period names
if (isRegistrationInGracePeriod(registration, event.block.timestamp)) {
throw new Error(
`Invariant(NameWrapper:NameWrapped): Cannot wrap direct-subname-of-registrar-managed-names in GRACE_PERIOD \n${toJson(registration)}`,
`Invariant(NameWrapper:NameWrapped): Cannot wrap direct-subname-of-registrar-managed-names in GRACE_PERIOD \n${toJson(registration, { pretty: true })}`,
);
}

// Invariant: cannot re-wrap, right? NameWrapped -> NameUnwrapped -> NameWrapped
if (registration.wrapped) {
throw new Error(
`Invariant(NameWrapper:NameWrapped): Re-wrapping already wrapped BaseRegistrar registration\n${toJson(registration)}`,
`Invariant(NameWrapper:NameWrapped): Re-wrapping already wrapped BaseRegistrar registration\n${toJson(registration, { pretty: true })}`,
);
}

// Invariant: BaseRegistrar always provides expiry
if (expiry === null) {
throw new Error(
`Invariant(NameWrapper:NameWrapped): Wrap of BaseRegistrar Registration does not include expiry!\n${toJson(registration)}`,
`Invariant(NameWrapper:NameWrapped): Wrap of BaseRegistrar Registration does not include expiry!\n${toJson(registration, { pretty: true })}`,
);
}

Expand All @@ -240,7 +240,7 @@ export default function () {
// Invariant: If there's an existing Registration, it should be expired
if (registration && !isFullyExpired) {
throw new Error(
`Invariant(NameWrapper:NameWrapped): NameWrapped but there's an existing unexpired non-BaseRegistrar Registration:\n${toJson({ registration, timestamp: event.block.timestamp })}`,
`Invariant(NameWrapper:NameWrapped): NameWrapped but there's an existing unexpired non-BaseRegistrar Registration:\n${toJson({ registration, timestamp: event.block.timestamp }, { pretty: true })}`,
);
}

Expand Down Expand Up @@ -327,7 +327,7 @@ export default function () {
// Invariant: must have a Registration
if (!registration) {
throw new Error(
`Invariant(NameWrapper:FusesSet): Registration expected:\n${toJson(registration)}`,
`Invariant(NameWrapper:FusesSet): Registration expected:\n${toJson(registration, { pretty: true })}`,
);
}

Expand Down Expand Up @@ -363,7 +363,7 @@ export default function () {
// Invariant: must have Registration
if (!registration) {
throw new Error(
`Invariant(NameWrapper:ExpiryExtended): Registration expected\n${toJson(registration)}`,
`Invariant(NameWrapper:ExpiryExtended): Registration expected\n${toJson(registration, { pretty: true })}`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
makeSubdomainNode,
} from "enssdk";

import { type EncodedReferrer, PluginName } from "@ensnode/ensnode-sdk";
import { type EncodedReferrer, PluginName, toJson } from "@ensnode/ensnode-sdk";

import { ensureDomainEvent } from "@/lib/ensv2/event-db-helpers";
import { ensureLabel, ensureUnknownLabel } from "@/lib/ensv2/label-db-helpers";
Expand All @@ -20,7 +20,6 @@ import {
ensIndexerSchema,
type IndexingEngineContext,
} from "@/lib/indexing-engines/ponder";
import { toJson } from "@/lib/json-stringify-with-bigints";
import { getManagedName } from "@/lib/managed-names";
import { namespaceContract } from "@/lib/plugin-helpers";
import type { EventWithArgs } from "@/lib/ponder-helpers";
Expand Down Expand Up @@ -120,13 +119,16 @@ export default function () {

if (!registration) {
throw new Error(
`Invariant(RegistrarController:NameRenewed): NameRenewed but no Registration.\n${toJson({
label,
labelHash,
managedNode,
node,
domainId,
})}`,
`Invariant(RegistrarController:NameRenewed): NameRenewed but no Registration.\n${toJson(
{
label,
labelHash,
managedNode,
node,
domainId,
},
{ pretty: true },
)}`,
);
}

Expand All @@ -142,6 +144,7 @@ export default function () {
domainId,
registration,
},
{ pretty: true },
)}`,
);
}
Expand Down
Loading
Loading