// Copyright (c) Mysten Labs, Inc. // SPDX-License-Identifier: Apache-2.0 import { toBase64 } from '@mysten/bcs'; import type { SerializedBcs } from '@mysten/bcs'; import { normalizeSuiAddress } from '../utils/sui-types.js'; import type { CallArg, ObjectRef, Reservation, WithdrawalTypeArg, WithdrawFrom, } from './data/internal.js'; function Pure(data: Uint8Array | SerializedBcs): Extract { return { $kind: 'Pure', Pure: { bytes: data instanceof Uint8Array ? toBase64(data) : data.toBase64(), }, }; } export const Inputs = { Pure, ObjectRef({ objectId, digest, version }: ObjectRef): Extract { return { $kind: 'Object', Object: { $kind: 'ImmOrOwnedObject', ImmOrOwnedObject: { digest, version, objectId: normalizeSuiAddress(objectId), }, }, }; }, SharedObjectRef({ objectId, mutable, initialSharedVersion, }: { objectId: string; mutable: boolean; initialSharedVersion: number | string; }): Extract { return { $kind: 'Object', Object: { $kind: 'SharedObject', SharedObject: { mutable, initialSharedVersion, objectId: normalizeSuiAddress(objectId), }, }, }; }, ReceivingRef({ objectId, digest, version }: ObjectRef): Extract { return { $kind: 'Object', Object: { $kind: 'Receiving', Receiving: { digest, version, objectId: normalizeSuiAddress(objectId), }, }, }; }, FundsWithdrawal({ reservation, typeArg, withdrawFrom, }: { reservation: Reservation; typeArg: WithdrawalTypeArg; withdrawFrom: WithdrawFrom; }): Extract { return { $kind: 'FundsWithdrawal', FundsWithdrawal: { reservation, typeArg, withdrawFrom, }, }; }, };