@cfxlabsinc/b2b-services
    Preparing search index...

    Class UtilaSweepWalletAdminService

    Hierarchy (View Summary)

    Index
    db: B2bDatabase
    • How many of a customer's deposit wallets are live, and how many are hidden.

      One scan with FILTER aggregates rather than two search calls: the customer hub renders this per panel open, and the deleted count is only meaningful next to the live one — "2, 1 deleted" is a single fact about the customer, so it should cost a single round trip. Exact, unlike counting a capped page.

      Parameters

      • args: { customerId: string }

      Returns Promise<{ ok: true; value: { deleted: number; live: number } }>

    • Parameters

      • args: { entityId: string; existingWalletId?: string; label?: string }
        • entityId: string
        • OptionalexistingWalletId?: string
        • Optionallabel?: string

          Label for a newly-created vault wallet; ignored when existingWalletId is given (that wallet already has a name we cannot change — Utila has no rename). Defaults to the entity's display name.

          This is the label only: SWEEP_WALLET_NAME_PREFIX is always applied on top, so an operator cannot accidentally mint a wallet that reads as custodial in a shared vault.

          Operator-supplied because an entity being given a replacement wallet cannot reuse the retired one's name while that wallet is still around, and only the operator knows what distinguishes this generation.

      Returns Promise<
          | { error: ServiceError; ok: false }
          | {
              ok: true;
              value: {
                  addresses: Record<UtilaBlockchain, UtilaSweepWalletAddress[]>;
                  createdAt: Date;
                  deletedAt: Date | null;
                  id: string;
                  updatedAt: Date;
                  vaultId: string;
              };
          },
      >

    • Soft-delete or restore a deposit wallet, and mirror the same transition onto the Utila wallet by archiving / un-archiving it.

      Deleting drops the wallet out of every consumer read — the customer dashboard stops offering it as a deposit target — and archives it in the vault, which also takes it out of listWallets (archived wallets are excluded unless showArchived is set) so a retired wallet cannot be offered back up for linking. Restoring is the exact inverse.

      The DB write comes first, deliberately. Archiving first and then failing the update would leave a wallet that is archived in the vault but still live in CFX — a customer's deposit page pointing at a retired wallet. In this order the worst case is the benign one: hidden in CFX, still un-archived in the vault, which a retry fixes.

      The Utila call is best-effort. It runs after a committed DB write, so there is nothing useful to propagate and no way to roll back; a vault outage must not stop an operator hiding addresses from a customer. It is also the reason this method still works on a stage with no signer credentials, where the call throws immediately. The outcome is reported as archiveFailed rather than swallowed, so the caller can say so.

      Parameters

      • args: { deleted: boolean; id: string }

      Returns Promise<
          | { ok: true; value: { archiveFailed: boolean; id: string } }
          | { error: ServiceError; ok: false },
      >

    • Parameters

      • args: { id: string }

      Returns Promise<
          | { error: ServiceError; ok: false }
          | {
              ok: true;
              value:
                  | {
                      addresses: Record<UtilaBlockchain, UtilaSweepWalletAddress[]>;
                      createdAt: Date;
                      deletedAt: Date | null;
                      id: string;
                      updatedAt: Date;
                      vaultId: string;
                  } & UtilaSweepWalletReferences
                  | null;
          },
      >

    • Wallets that exist in the sweep vault but aren't linked to an entity yet — the candidate set for the link flow. Sourced live from Utila (the vault is the authority on what exists) minus every wallet id already in the table.

      The "already linked" read is deliberately unfiltered: a soft-deleted row still owns its Utila wallet, so offering it up for re-linking would produce two rows pointing at one wallet. Restoring the existing row is the correct operator move there, and keeping it out of this list is what forces it.

      Returns Promise<
          | { error: ServiceError; ok: false }
          | { ok: true; value: { displayName: string; id: string }[] },
      >

    • Parameters

      • __namedParameters: {
            createdAt?: DbTimestampCriteria;
            customerIds?: string[];
            entityIds?: string[];
            entityTypes?: ("PERSON" | "BUSINESS")[];
            ids?: string[];
            includeDeleted?: boolean;
            orderBy?: DbOrderByCriterion<
                Omit<
                    PgTableWithColumns<
                        {
                            columns: {
                                createdAt: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    SetHasDefault<SetNotNull<(...)>>,
                                    {
                                        data: Date;
                                        dataType: "object date";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                customerId: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    SetNotNull<PgIntegerBuilder>,
                                    {
                                        data: number;
                                        dataType: "number int32";
                                        driverParam: (...) | (...);
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                data: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    SetNotNull<Set$Type<(...), (...)>>,
                                    {
                                        data: { addresses: ... };
                                        dataType: "object json";
                                        driverParam: unknown;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                deletedAt: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    PgTimestampBuilder,
                                    {
                                        data: Date;
                                        dataType: "object date";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                id: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    HasIdentity<SetIsPrimaryKey<(...)>, "byDefault">,
                                    {
                                        data: number;
                                        dataType: "number int32";
                                        driverParam: (...) | (...);
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: "byDefault";
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                identityId: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    PgIntegerBuilder,
                                    {
                                        data: number;
                                        dataType: "number int32";
                                        driverParam: (...)
                                        | (...);
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                organizationId: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    PgIntegerBuilder,
                                    {
                                        data: number;
                                        dataType: "number int32";
                                        driverParam: (...)
                                        | (...);
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: false;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                updatedAt: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    SetHasDefault<SetHasDefault<(...)>>,
                                    {
                                        data: Date;
                                        dataType: "object date";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: true;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                vaultId: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    SetNotNull<PgTextBuilder<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                                walletId: PgBuildColumn<
                                    "utila_sweep_wallet",
                                    SetNotNull<PgTextBuilder<(...)>>,
                                    {
                                        data: string;
                                        dataType: "string";
                                        driverParam: string;
                                        enumValues: undefined;
                                        generated: undefined;
                                        hasDefault: false;
                                        hasRuntimeDefault: false;
                                        identity: undefined;
                                        isAutoincrement: false;
                                        isPrimaryKey: false;
                                        name: string;
                                        notNull: true;
                                        tableName: "utila_sweep_wallet";
                                    },
                                >;
                            };
                            dialect: "pg";
                            name: "utila_sweep_wallet";
                            schema: "b2b";
                        },
                    >,
                    "enableRLS",
                >,
                "createdAt"
                | "updatedAt",
            >[];
            page?: number;
            pageSize?: number;
            q?: string;
            updatedAt?: DbTimestampCriteria;
        }
        • OptionalcreatedAt?: DbTimestampCriteria
        • OptionalcustomerIds?: string[]
        • OptionalentityIds?: string[]
        • OptionalentityTypes?: ("PERSON" | "BUSINESS")[]

          Narrow to wallets owned by people (identity_id) or by businesses (organization_id). Distinct from entityIds, which names specific entities — this is the "all people" / "all businesses" cut.

        • Optionalids?: string[]
        • OptionalincludeDeleted?: boolean

          Include soft-deleted wallets. Off by default so every caller that forgets it gets the live set. Admin-only: the consumer service has no such flag, because a deleted wallet is precisely one a customer must not see.

        • OptionalorderBy?: DbOrderByCriterion<
              Omit<
                  PgTableWithColumns<
                      {
                          columns: {
                              createdAt: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  SetHasDefault<SetNotNull<(...)>>,
                                  {
                                      data: Date;
                                      dataType: "object date";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              customerId: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  SetNotNull<PgIntegerBuilder>,
                                  {
                                      data: number;
                                      dataType: "number int32";
                                      driverParam: (...) | (...);
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              data: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  SetNotNull<Set$Type<(...), (...)>>,
                                  {
                                      data: { addresses: ... };
                                      dataType: "object json";
                                      driverParam: unknown;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              deletedAt: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  PgTimestampBuilder,
                                  {
                                      data: Date;
                                      dataType: "object date";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              id: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  HasIdentity<SetIsPrimaryKey<(...)>, "byDefault">,
                                  {
                                      data: number;
                                      dataType: "number int32";
                                      driverParam: (...) | (...);
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: "byDefault";
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              identityId: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  PgIntegerBuilder,
                                  {
                                      data: number;
                                      dataType: "number int32";
                                      driverParam: (...)
                                      | (...);
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              organizationId: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  PgIntegerBuilder,
                                  {
                                      data: number;
                                      dataType: "number int32";
                                      driverParam: (...)
                                      | (...);
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: false;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              updatedAt: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  SetHasDefault<SetHasDefault<(...)>>,
                                  {
                                      data: Date;
                                      dataType: "object date";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: true;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              vaultId: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  SetNotNull<PgTextBuilder<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                              walletId: PgBuildColumn<
                                  "utila_sweep_wallet",
                                  SetNotNull<PgTextBuilder<(...)>>,
                                  {
                                      data: string;
                                      dataType: "string";
                                      driverParam: string;
                                      enumValues: undefined;
                                      generated: undefined;
                                      hasDefault: false;
                                      hasRuntimeDefault: false;
                                      identity: undefined;
                                      isAutoincrement: false;
                                      isPrimaryKey: false;
                                      name: string;
                                      notNull: true;
                                      tableName: "utila_sweep_wallet";
                                  },
                              >;
                          };
                          dialect: "pg";
                          name: "utila_sweep_wallet";
                          schema: "b2b";
                      },
                  >,
                  "enableRLS",
              >,
              "createdAt"
              | "updatedAt",
          >[]
        • Optionalpage?: number

          Defaults to 1

        • OptionalpageSize?: number

          Defaults to 10

        • Optionalq?: string

          Case-insensitive substring over the Utila wallet id, the owning customer's name, the entity's name, and the derived deposit addresses — an operator most often arrives holding an address off a block explorer and needs the wallet it belongs to.

        • OptionalupdatedAt?: DbTimestampCriteria

      Returns Promise<
          {
              ok: true;
              value: {
                  hasNext: boolean;
                  items: (
                      {
                          addresses: Record<UtilaBlockchain, UtilaSweepWalletAddress[]>;
                          createdAt: Date;
                          deletedAt: Date | null;
                          id: string;
                          updatedAt: Date;
                          vaultId: string;
                      } & UtilaSweepWalletReferences
                  )[];
                  total: number;
              };
          },
      >

    • Hide or restore ONE derived address, leaving the wallet and every other chain alone.

      The wallet-level delete above is all-or-nothing; this is the same contract one level down, stored as a deletedAt stamp on the address entry inside the data jsonb. Utila is not called and the vault is untouched: the address keeps existing, so funds already sent to it still arrive and sweep. What changes is that CFX stops offering it on the customer's deposit page.

      Read-modify-write under a row lock, because every chain's addresses share one jsonb blob — two concurrent hides on different chains would otherwise race, and the second write would silently drop the first.

      Parameters

      • args: { address: string; chain: string; deleted: boolean; id: string }

      Returns Promise<
          | { ok: true; value: { address: string } }
          | { error: ServiceError; ok: false },
      >

    • How many chains a fully-derived sweep wallet has addresses on — the denominator for "3 chains" on a list row, which is otherwise unjudgeable.

      Comes from the client's supported-chain set, which is a pure function of the vault env (22 chains on prod, 7 on dev) and needs no credentials and no network. Deliberately NOT the b2b.chain reference table: that lists every chain CFX knows about, which would give a wrong (much larger) denominator.

      Returns number